aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorVijay Dev <vijaydev.cse@gmail.com>2012-12-01 23:00:47 +0530
committerVijay Dev <vijaydev.cse@gmail.com>2012-12-01 23:00:47 +0530
commit0181c2da977fc3de4e4c4eac602b26ff180cda2c (patch)
tree4ff327e807bc7729c5b99bf261bdbc5178faf227 /activerecord/lib
parentfb42520252477d83560f2e2a2550c7f377e07bc1 (diff)
parent9685019c4a15eb0222984748e7413dc5920195f4 (diff)
downloadrails-0181c2da977fc3de4e4c4eac602b26ff180cda2c.tar.gz
rails-0181c2da977fc3de4e4c4eac602b26ff180cda2c.tar.bz2
rails-0181c2da977fc3de4e4c4eac602b26ff180cda2c.zip
Merge branch 'master' of github.com:lifo/docrails
Conflicts: guides/source/active_record_validations.md
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/collection_proxy.rb16
-rw-r--r--activerecord/lib/active_record/relation/calculations.rb6
2 files changed, 16 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb
index 6e05af894e..7f9628499c 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 <tt>SELECT COUNT(*)</tt> query.
+ # it executes a <tt>SELECT COUNT(*)</tt> query. Else it 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 @@ 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
@@ -718,7 +723,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 <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
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb
index 72b035a023..99e77e007a 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 <tt>pluck</tt> as a shortcut to select a single attribute without
- # loading a bunch of records just to grab one attribute you want.
+ # Use <tt>pluck</tt> 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 <tt>Array</tt> 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 they can be deduced. Plucking an SQL fragment
# returns String values by default.
#
# Examples: