Permalink
Browse files

add documentation to CollectionProxy#empty?

  • Loading branch information...
1 parent 97b95c3 commit 61a7a9f38bfce21bbeb1dd09efabc4f1002cc00d Francesco Rodriguez committed Nov 29, 2012
Showing with 6 additions and 1 deletion.
  1. +6 −1 activerecord/lib/active_record/associations/collection_proxy.rb
@@ -718,7 +718,12 @@ def length
@association.length
end
- # Returns +true+ if the collection is empty.
+ # 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>.
#
# class Person < ActiveRecord::Base
# has_many :pets

0 comments on commit 61a7a9f

Please sign in to comment.