Permalink
Browse files

add documentation to CollectionProxy #length and #size methods [ci skip]

  • Loading branch information...
Francesco Rodriguez
Francesco Rodriguez committed Nov 29, 2012
1 parent 61a7a9f commit abdfffa2139355d7ccb6d8fd91a6bb21f2f1b8d8
Showing with 7 additions and 2 deletions.
  1. +7 −2 activerecord/lib/active_record/associations/collection_proxy.rb
@@ -672,7 +672,11 @@ def count(column_name = nil, options = {})
end
# Returns the size of the collection. If the collection hasn't been loaded,
- # it executes a <tt>SELECT COUNT(*)</tt> query.
+ # it executes a <tt>SELECT COUNT(*)</tt> query. If it has, calls <tt>collection.size</tt>.
+ #
+ # If the collection has been already loaded +size+ and +length+ are
+ # equivalent. If not and you are going to need the records anyway
+ # +length+ will take one less query. Otherwise +size+ is more efficient.
#
# class Person < ActiveRecord::Base
# has_many :pets
@@ -697,7 +701,8 @@ def size
# Returns the size of the collection calling +size+ on the target.
# If the collection has been already loaded, +length+ and +size+ are
- # equivalent.
+ # equivalent. If not and you are going to need the records anyway this
+ # method will take one less query. Otherwise +size+ is more efficient.
#
# class Person < ActiveRecord::Base
# has_many :pets

0 comments on commit abdfffa

Please sign in to comment.