From 7aad851c2e0d4579aa33a54a069a767b53cca406 Mon Sep 17 00:00:00 2001 From: Brian Lopez Date: Fri, 30 Apr 2010 14:59:41 -0700 Subject: Allow pre-casted values (other than nil) to pass through from calculations un-touched [#4514 state:committed] Signed-off-by: Jeremy Kemper --- activerecord/lib/active_record/relation/calculations.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index a5ea6e7e3a..8ab5eaa724 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -239,11 +239,15 @@ module ActiveRecord end def type_cast_calculated_value(value, column, operation = nil) - case operation - when 'count' then value.to_i - when 'sum' then type_cast_using_column(value || '0', column) - when 'average' then value && (value.is_a?(Fixnum) ? value.to_f : value).to_d - else type_cast_using_column(value, column) + if value.is_a?(String) || value.nil? + case operation + when 'count' then value.to_i + when 'sum' then type_cast_using_column(value || '0', column) + when 'average' then value && (value.is_a?(Fixnum) ? value.to_f : value).to_d + else type_cast_using_column(value, column) + end + else + value end end -- cgit v1.2.3