refactoring to remove crazy logic

This commit is contained in:
Aaron Patterson
2010-09-28 16:14:39 -07:00
parent c2cad2d97e
commit e6ca7e7197
2 changed files with 6 additions and 9 deletions

View File

@@ -191,7 +191,11 @@ module ActiveRecord
end
# Postgresql doesn't like ORDER BY when there are no GROUP BY
relation = except(:order).select(operation == 'count' ? column.count(distinct) : column.send(operation))
relation = except(:order)
select_value = operation == 'count' ? column.count(distinct) : column.send(operation)
relation.select_values = [select_value]
type_cast_calculated_value(@klass.connection.select_value(relation.to_sql), column_for(column_name), operation)
end

View File

@@ -259,14 +259,7 @@ module ActiveRecord
def build_select(arel, selects)
unless selects.empty?
@implicit_readonly = false
# TODO: fix this ugly hack, we should refactor the callers to get an Arel compatible array.
# Before this change we were passing to Arel the last element only, and Arel is capable of handling an array
case select = selects.last
when Arel::Expression, Arel::SqlLiteral
arel.project(select)
else
arel.project(*selects)
end
arel.project(*selects)
else
arel.project(Arel::SqlLiteral.new(@klass.quoted_table_name + '.*'))
end