aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2014-05-13 09:04:46 +0200
committerYves Senn <yves.senn@gmail.com>2014-05-13 09:04:52 +0200
commitef8ac1f88522d098534361a10c2da50bc81753fd (patch)
tree8a677561e496e5d9a3084f27121532a2e92ad7b8
parent55b1f21ae361b585e3ff0e991703a47ab4887dd0 (diff)
downloadrails-ef8ac1f88522d098534361a10c2da50bc81753fd.tar.gz
rails-ef8ac1f88522d098534361a10c2da50bc81753fd.tar.bz2
rails-ef8ac1f88522d098534361a10c2da50bc81753fd.zip
docs, explain usage of `count` + `select`. Closes #15065. [ci skip]
-rw-r--r--activerecord/lib/active_record/relation/calculations.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb
index 42c9881b48..56cf9bcd27 100644
--- a/activerecord/lib/active_record/relation/calculations.rb
+++ b/activerecord/lib/active_record/relation/calculations.rb
@@ -19,6 +19,14 @@ module ActiveRecord
#
# Person.group(:city).count
# # => { 'Rome' => 5, 'Paris' => 3 }
+ #
+ # If +count+ is used with +select+, it will count the selected columns:
+ #
+ # Person.select(:age).count
+ # # => counts the number of different age values
+ #
+ # Note: not all valid +select+ expressions are valid +count+ expressions. The specifics differ
+ # between databases. In invalid cases, an error from the databsae is thrown.
def count(column_name = nil, options = {})
# TODO: Remove options argument as soon we remove support to
# activerecord-deprecated_finders.