From 4513cc142c2cce675ea5fa63926950dc240e9aac Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Wed, 22 Sep 2010 10:59:29 -0300 Subject: Goodbye inject, hello map. Signed-off-by: Santiago Pastorino --- activerecord/lib/active_record/relation/calculations.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index 398ab75b69..12a2c6aec3 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -225,13 +225,11 @@ module ActiveRecord key_records = key_records.inject({}) { |hsh, r| hsh.merge(r.id => r) } end - calculated_data.inject(ActiveSupport::OrderedHash.new) do |all, row| - key = type_cast_calculated_value(row[group_alias], group_column) - key = key_records[key] if associated - value = row[aggregate_alias] - all[key] = type_cast_calculated_value(value, column_for(column_name), operation) - all - end + ActiveSupport::OrderedHash[calculated_data.map do |row| + key = type_cast_calculated_value(row[group_alias], group_column) + key = key_records[key] if associated + [key, type_cast_calculated_value(row[aggregate_alias], column_for(column_name), operation)] + end] end # Converts the given keys to the value that the database adapter returns as -- cgit v1.2.3