From a8c2981f62555a7ea7e5b378509fca6009ba8a8e Mon Sep 17 00:00:00 2001 From: Maurizio De Santis Date: Thu, 7 Feb 2013 21:24:45 +0100 Subject: Add ActiveRecord.count documentation when used on group relations --- activerecord/lib/active_record/relation/calculations.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index f10c290755..3fc079d84c 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -13,6 +13,12 @@ module ActiveRecord # # Person.count(:age, distinct: true) # # => counts the number of different age values + # + # If used on a +group+, it returns a Hash whose keys represent the aggregated column, + # and the values are the respective amounts: + # + # Person.group(:city).count + # # => { 'Rome' => 5, 'Paris' => 3 } def count(column_name = nil, options = {}) column_name, options = nil, column_name if column_name.is_a?(Hash) calculate(:count, column_name, options) -- cgit v1.2.3