From abdfffa2139355d7ccb6d8fd91a6bb21f2f1b8d8 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Thu, 29 Nov 2012 12:58:31 -0500 Subject: add documentation to CollectionProxy #length and #size methods [ci skip] --- activerecord/lib/active_record/associations/collection_proxy.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'activerecord/lib/active_record/associations') diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb index d57fa40b91..a9a4eb8728 100644 --- a/activerecord/lib/active_record/associations/collection_proxy.rb +++ b/activerecord/lib/active_record/associations/collection_proxy.rb @@ -672,7 +672,11 @@ module ActiveRecord end # Returns the size of the collection. If the collection hasn't been loaded, - # it executes a SELECT COUNT(*) query. + # it executes a SELECT COUNT(*) query. If it has, calls collection.size. + # + # 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 @@ module ActiveRecord # 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 -- cgit v1.2.3