Permalink
Browse files

Add ActiveRecord.count documentation when used on group relations

  • Loading branch information...
1 parent d47b90e commit a8c2981f62555a7ea7e5b378509fca6009ba8a8e @mdesantis mdesantis committed Feb 7, 2013
Showing with 6 additions and 0 deletions.
  1. +6 −0 activerecord/lib/active_record/relation/calculations.rb
@@ -13,6 +13,12 @@ module Calculations
#
# 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)

0 comments on commit a8c2981

Please sign in to comment.