diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2010-01-19 15:50:47 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2010-01-19 15:50:47 +0530 |
commit | 4148c686ec2582c457adf277dec5b3ff496627c8 (patch) | |
tree | 43e2c28a1f1561c157c759adf3a23d8b3f4e99b9 /activerecord/lib/active_record/calculations.rb | |
parent | ed8501ef16fb2f5e4bd4d987740f5e5f62978400 (diff) | |
download | rails-4148c686ec2582c457adf277dec5b3ff496627c8.tar.gz rails-4148c686ec2582c457adf277dec5b3ff496627c8.tar.bz2 rails-4148c686ec2582c457adf277dec5b3ff496627c8.zip |
Delegate :average, :minimum, :maximum, :sum to Relation
Diffstat (limited to 'activerecord/lib/active_record/calculations.rb')
-rw-r--r-- | activerecord/lib/active_record/calculations.rb | 36 |
1 files changed, 1 insertions, 35 deletions
diff --git a/activerecord/lib/active_record/calculations.rb b/activerecord/lib/active_record/calculations.rb index fc6cb793ab..db1f332336 100644 --- a/activerecord/lib/active_record/calculations.rb +++ b/activerecord/lib/active_record/calculations.rb @@ -64,41 +64,7 @@ module ActiveRecord 0 end - # Calculates the average value on a given column. The value is returned as - # a float, or +nil+ if there's no row. See +calculate+ for examples with - # options. - # - # Person.average('age') # => 35.8 - def average(column_name, options = {}) - calculate(:average, column_name, options) - end - - # Calculates the minimum value on a given column. The value is returned - # with the same data type of the column, or +nil+ if there's no row. See - # +calculate+ for examples with options. - # - # Person.minimum('age') # => 7 - def minimum(column_name, options = {}) - calculate(:minimum, column_name, options) - end - - # Calculates the maximum value on a given column. The value is returned - # with the same data type of the column, or +nil+ if there's no row. See - # +calculate+ for examples with options. - # - # Person.maximum('age') # => 93 - def maximum(column_name, options = {}) - calculate(:maximum, column_name, options) - end - - # Calculates the sum of values on a given column. The value is returned - # with the same data type of the column, 0 if there's no row. See - # +calculate+ for examples with options. - # - # Person.sum('age') # => 4562 - def sum(column_name, options = {}) - calculate(:sum, column_name, options) - end + delegate :average, :minimum, :maximum, :sum, :to => :scoped # This calculates aggregate values in the given column. Methods for count, sum, average, minimum, and maximum have been added as shortcuts. # Options such as <tt>:conditions</tt>, <tt>:order</tt>, <tt>:group</tt>, <tt>:having</tt>, and <tt>:joins</tt> can be passed to customize the query. |