Permalink
Browse files

Goodbye inject, hello map.

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
  • Loading branch information...
1 parent 109c37b commit 68e1b5a3976bbb7dc2dada68e34db0b30867a1e9 @miloops miloops committed with spastorino Sep 22, 2010
Showing with 5 additions and 7 deletions.
  1. +5 −7 activerecord/lib/active_record/relation/calculations.rb
@@ -225,13 +225,11 @@ def execute_grouped_calculation(operation, column_name) #:nodoc:
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

0 comments on commit 68e1b5a

Please sign in to comment.