diff options
author | Bogdan Gusiev <agresso@gmail.com> | 2011-07-05 14:36:20 +0300 |
---|---|---|
committer | Bogdan Gusiev <agresso@gmail.com> | 2011-07-05 14:36:20 +0300 |
commit | e7bec4e435d05eb517f515a4661186ce8d088238 (patch) | |
tree | fc85f69a839e53efdb9662de91a249c860b634fe /activerecord/lib/active_record | |
parent | 289b5253ce476410ff78a5f55248c5a4e6a60223 (diff) | |
download | rails-e7bec4e435d05eb517f515a4661186ce8d088238.tar.gz rails-e7bec4e435d05eb517f515a4661186ce8d088238.tar.bz2 rails-e7bec4e435d05eb517f515a4661186ce8d088238.zip |
Fixed AR::Relation#sum compatibility with Array#sum
In order make Relation behavior closer to Array
Made Relation#sum to accept block and delegate it to Array#sum
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/relation/calculations.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index 9c5f603c01..0ac821b2d7 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -89,8 +89,12 @@ module ActiveRecord # +calculate+ for examples with options. # # Person.sum('age') # => 4562 - def sum(column_name, options = {}) - calculate(:sum, column_name, options) + def sum(*args) + if block_given? + self.to_a.sum(*args) {|*block_args| yield(*block_args)} + else + calculate(:sum, *args) + end end # This calculates aggregate values in the given column. Methods for count, sum, average, |