From e6ca7e7197f46df0e538f50cea236cb923e4b47f Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 28 Sep 2010 16:14:39 -0700 Subject: refactoring to remove crazy logic --- activerecord/lib/active_record/relation/calculations.rb | 6 +++++- activerecord/lib/active_record/relation/query_methods.rb | 9 +-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index 0b3d1ed3ff..03862c78e4 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -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 diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index e2b1330c24..bdd171135c 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -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 -- cgit v1.2.3