From 1f802968c5a803f649fc27c7295b01aef3af6514 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 30 May 2007 06:57:04 +0000 Subject: Calculations: return nil average instead of 0 when there are no rows to average. Closes #8298. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6904 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/calculations.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/calculations.rb b/activerecord/lib/active_record/calculations.rb index a54ef468e0..09c0c979e6 100644 --- a/activerecord/lib/active_record/calculations.rb +++ b/activerecord/lib/active_record/calculations.rb @@ -265,7 +265,7 @@ module ActiveRecord operation = operation.to_s.downcase case operation when 'count' then value.to_i - when 'avg' then value.to_f + when 'avg' then value && value.to_f else column ? column.type_cast(value) : value end end -- cgit v1.2.3