Skip to content

Commit

Permalink
Goodbye inject, hello map.
Browse files Browse the repository at this point in the history
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
  • Loading branch information
miloops authored and spastorino committed Sep 24, 2010
1 parent 109c37b commit 68e1b5a
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions activerecord/lib/active_record/relation/calculations.rb
Expand Up @@ -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
Expand Down

0 comments on commit 68e1b5a

Please sign in to comment.