diff options
author | Emilio Tagua <miloops@gmail.com> | 2010-09-22 10:59:29 -0300 |
---|---|---|
committer | Santiago Pastorino <santiago@wyeworks.com> | 2010-09-22 18:08:02 -0300 |
commit | 4513cc142c2cce675ea5fa63926950dc240e9aac (patch) | |
tree | 82ffc722d9be7085d3616e2825d486e998592d4b | |
parent | 569be76ed6e813c854ac31958f547a5d4acfb5da (diff) | |
download | rails-4513cc142c2cce675ea5fa63926950dc240e9aac.tar.gz rails-4513cc142c2cce675ea5fa63926950dc240e9aac.tar.bz2 rails-4513cc142c2cce675ea5fa63926950dc240e9aac.zip |
Goodbye inject, hello map.
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
-rw-r--r-- | activerecord/lib/active_record/relation/calculations.rb | 12 |
1 files changed, 5 insertions, 7 deletions
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 |