From ad9983f625ea414c5b7bbc0fd12be17ec04fc590 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Sat, 17 Nov 2012 19:08:07 -0200 Subject: 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. --- activerecord/lib/active_record/associations.rb | 2 +- activerecord/lib/active_record/relation/calculations.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record') 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) -- cgit v1.2.3