From 95d5d9b6c48c08f1fba0c77ecbc97b62b2603824 Mon Sep 17 00:00:00 2001 From: Ken Collins Date: Thu, 3 Feb 2011 15:07:03 -0500 Subject: The type_cast_calculated_value method will trust DB types before casting to a BigDecimal. [#6365 state:committed] Signed-off-by: Santiago Pastorino --- activerecord/lib/active_record/relation/calculations.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/relation') diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index b75a65e3ca..abc4c54109 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -285,7 +285,7 @@ module ActiveRecord case operation when 'count' then value.to_i when 'sum' then type_cast_using_column(value || '0', column) - when 'average' then value.try(:to_d) + when 'average' then value.respond_to?(:to_d) ? value.to_d : value else type_cast_using_column(value, column) end end -- cgit v1.2.3