From bd75a722a2e9f979bfd1b1d89442e4dd6f3e3af7 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Mon, 2 Jun 2008 20:40:25 +0100 Subject: Ensure AR#sum result is typecasted properly --- activerecord/lib/active_record/calculations.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/calculations.rb b/activerecord/lib/active_record/calculations.rb index 889b7845fb..caa8c539d5 100644 --- a/activerecord/lib/active_record/calculations.rb +++ b/activerecord/lib/active_record/calculations.rb @@ -265,8 +265,9 @@ module ActiveRecord def type_cast_calculated_value(value, column, operation = nil) operation = operation.to_s.downcase case operation - when 'count', 'sum' then value.to_i - when 'avg' then value && value.to_f + when 'count' then value.to_i + when 'sum' then value =~ /\./ ? value.to_f : value.to_i + when 'avg' then value && value.to_f else column ? column.type_cast(value) : value end end -- cgit v1.2.3