From 9a269dad3fd39664595d4e99d60f5a902c4da470 Mon Sep 17 00:00:00 2001 From: Ken Collins Date: Fri, 7 Nov 2008 14:51:21 -0500 Subject: [PATCH] If average value from DB is 0, make sure to convert it to a 0.0 float before calling #to_d on it. --- activerecord/lib/active_record/calculations.rb | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/activerecord/lib/active_record/calculations.rb b/activerecord/lib/active_record/calculations.rb index 5e33cf1..dd90580 100644 --- a/activerecord/lib/active_record/calculations.rb +++ b/activerecord/lib/active_record/calculations.rb @@ -286,7 +286,7 @@ module ActiveRecord case operation when 'count' then value.to_i when 'sum' then type_cast_using_column(value || '0', column) - when 'avg' then value && value.to_d + when 'avg' then value && value.to_f.to_d else type_cast_using_column(value, column) end end -- 1.6.0