Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
avoid calling to_sql when we can
  • Loading branch information
tenderlove committed Sep 29, 2010
1 parent c493624 commit 93096ae
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions activerecord/lib/active_record/relation/calculations.rb
Expand Up @@ -208,12 +208,12 @@ def execute_grouped_calculation(operation, column_name) #:nodoc:
aggregate_alias = column_alias_for(operation, column_name)

select_statement = if operation == 'count' && column_name == :all
"COUNT(*) AS count_all"
["COUNT(*) AS count_all"]
else
Arel::Attribute.new(@klass.unscoped.table, column_name).send(operation).as(aggregate_alias).to_sql
[Arel::Attribute.new(@klass.unscoped.table, column_name).send(operation).as(aggregate_alias)]
end

select_statement << ", #{group_field} AS #{group_alias}"
select_statement << "#{group_field} AS #{group_alias}"

relation = except(:group).select(select_statement).group(group)

Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/relation/query_methods.rb
Expand Up @@ -36,7 +36,7 @@ def select(value = Proc.new)
to_a.select {|*block_args| value.call(*block_args) }
else
relation = clone
relation.select_values += [value]
relation.select_values += Array.wrap(value)
relation
end
end
Expand Down

0 comments on commit 93096ae

Please sign in to comment.