From 61a7a9f38bfce21bbeb1dd09efabc4f1002cc00d Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Thu, 29 Nov 2012 12:51:31 -0500 Subject: add documentation to CollectionProxy#empty? --- activerecord/lib/active_record/associations/collection_proxy.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb index e444b0ed83..d57fa40b91 100644 --- a/activerecord/lib/active_record/associations/collection_proxy.rb +++ b/activerecord/lib/active_record/associations/collection_proxy.rb @@ -718,7 +718,12 @@ module ActiveRecord @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 :counter_sql option is provided, it is equivalent + # to collection.size.zero?. If the collection has not been loaded, + # it is equivalent to collection.exists?. If the collection has + # not already been loaded and you are going to fetch the records anyway it + # is better to check collection.length.zero?. # # class Person < ActiveRecord::Base # has_many :pets -- cgit v1.2.3 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') 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 From daab9bba887ec0682620087c39a0b4c097fc6efc Mon Sep 17 00:00:00 2001 From: Florent Guilleux Date: Sat, 1 Dec 2012 11:23:02 -0500 Subject: Fix Calculations#pluck doc to mention several attributes can be selected [ci skip] --- activerecord/lib/active_record/relation/calculations.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index 72b035a023..d969660a8a 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -111,8 +111,8 @@ module ActiveRecord 0 end - # Use pluck as a shortcut to select a single attribute without - # loading a bunch of records just to grab one attribute you want. + # Use pluck as a shortcut to select one or more attributes without + # loading a bunch of records just to grab the attributes you want. # # Person.pluck(:name) # @@ -121,7 +121,7 @@ module ActiveRecord # Person.all.map(&:name) # # Pluck returns an Array of attribute values type-casted to match - # the plucked column name, if it can be deduced. Plucking an SQL fragment + # the plucked column names, if it can be deduced. Plucking an SQL fragment # returns String values by default. # # Examples: -- cgit v1.2.3 From 9685019c4a15eb0222984748e7413dc5920195f4 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 1 Dec 2012 22:59:10 +0530 Subject: copy edits [ci skip] --- activerecord/lib/active_record/associations/collection_proxy.rb | 2 +- activerecord/lib/active_record/relation/calculations.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb index a9a4eb8728..07a5d07256 100644 --- a/activerecord/lib/active_record/associations/collection_proxy.rb +++ b/activerecord/lib/active_record/associations/collection_proxy.rb @@ -672,7 +672,7 @@ module ActiveRecord end # Returns the size of the collection. If the collection hasn't been loaded, - # it executes a SELECT COUNT(*) query. If it has, calls collection.size. + # it executes a SELECT COUNT(*) query. Else it 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 diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index d969660a8a..99e77e007a 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -121,7 +121,7 @@ module ActiveRecord # Person.all.map(&:name) # # Pluck returns an Array of attribute values type-casted to match - # the plucked column names, if it can be deduced. Plucking an SQL fragment + # the plucked column names, if they can be deduced. Plucking an SQL fragment # returns String values by default. # # Examples: -- cgit v1.2.3