diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-11-17 19:08:07 -0200 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-11-21 22:21:01 -0200 |
commit | ad9983f625ea414c5b7bbc0fd12be17ec04fc590 (patch) | |
tree | 352c4e140b1d689ad37ce6e4099eff9d7f061c56 /activerecord/lib | |
parent | 76a6bfd6c8dc9e3c27779a39b3e04402e20f0eaa (diff) | |
download | rails-ad9983f625ea414c5b7bbc0fd12be17ec04fc590.tar.gz rails-ad9983f625ea414c5b7bbc0fd12be17ec04fc590.tar.bz2 rails-ad9983f625ea414c5b7bbc0fd12be17ec04fc590.zip |
Deprecate Relation#sum with a block.
To perform a sum calculation over the array of elements, use to_a.sum(&block).
Please check the discussion in f9cb645dfcb5cc89f59d2f8b58a019486c828c73
for more context.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations.rb | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation/calculations.rb | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 651b17920c..d8b6d7a86b 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -234,7 +234,7 @@ module ActiveRecord # others.size | X | X | X # others.length | X | X | X # others.count | X | X | X - # others.sum(args*,&block) | X | X | X + # others.sum(*args) | X | X | X # others.empty? | X | X | X # others.clear | X | X | X # others.delete(other,other,...) | X | X | X diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index 24f3c128d1..72b035a023 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -1,3 +1,5 @@ +require 'active_support/deprecation' + module ActiveRecord module Calculations # Count the records. @@ -51,6 +53,10 @@ module ActiveRecord # Person.sum('age') # => 4562 def sum(*args) if block_given? + ActiveSupport::Deprecation.warn( + "Calling #sum with a block is deprecated and will be removed in Rails 4.1. " \ + "If you want to perform sum calculation over the array of elements, use `to_a.sum(&block)`." + ) self.to_a.sum(*args) {|*block_args| yield(*block_args)} else calculate(:sum, *args) |