提交 6126f02c 编写于 作者: J Jon Leighton

Merge pull request #7270 from beerlington/use_exists_for_empty

Changing AR:CollectionAssociation#empty? to use #exists?
......@@ -270,12 +270,20 @@ def length
load_target.size
end
# Returns true if the collection is empty. Equivalent to
# <tt>collection.size.zero?</tt>. If the collection has not been already
# Returns true if the collection is empty.
#
# If the collection has been loaded or the <tt>:counter_sql</tt> option
# is provided, it is equivalent to <tt>collection.size.zero?</tt>. If the
# collection has not been loaded, it is equivalent to
# <tt>collection.exists?</tt>. If the collection has not already been
# loaded and you are going to fetch the records anyway it is better to
# check <tt>collection.length.zero?</tt>.
def empty?
size.zero?
if loaded? || options[:counter_sql]
size.zero?
else
!scope.exists?
end
end
# Returns true if the collections is not empty.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册