Permalink
Browse files

create fewer relation objects

  • Loading branch information...
1 parent ef8b845 commit d5a8bdb2e21bc9b22241b9e2b604e88b76398339 @tenderlove tenderlove committed Nov 15, 2012
Showing with 6 additions and 3 deletions.
  1. +6 −3 activerecord/lib/active_record/relation/calculations.rb
@@ -273,7 +273,9 @@ def execute_grouped_calculation(operation, column_name, distinct) #:nodoc:
group_fields = group_attrs
end
- group_aliases = group_fields.map { |field| column_alias_for(field) }
+ group_aliases = group_fields.map { |field|
+ column_alias_for(field)
+ }
group_columns = group_aliases.zip(group_fields).map { |aliaz,field|
[aliaz, column_for(field)]
}
@@ -283,7 +285,7 @@ def execute_grouped_calculation(operation, column_name, distinct) #:nodoc:
if operation == 'count' && column_name == :all
aggregate_alias = 'count_all'
else
- aggregate_alias = column_alias_for(operation, column_name)
+ aggregate_alias = column_alias_for([operation, column_name].join(' '))
end
select_values = [
@@ -302,7 +304,8 @@ def execute_grouped_calculation(operation, column_name, distinct) #:nodoc:
end
}
- relation = except(:group).group(group)
+ relation = except(:group)
+ relation.group_values = group
relation.select_values = select_values
calculated_data = @klass.connection.select_all(relation, nil, bind_values)

0 comments on commit d5a8bdb

Please sign in to comment.