aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-09-28 16:14:39 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-09-28 16:14:39 -0700
commite6ca7e7197f46df0e538f50cea236cb923e4b47f (patch)
tree27e082f1bd6e0d11932eaeb00401801584a964d1 /activerecord
parentc2cad2d97e5feb872ac9222d8f4e393201f4ad18 (diff)
downloadrails-e6ca7e7197f46df0e538f50cea236cb923e4b47f.tar.gz
rails-e6ca7e7197f46df0e538f50cea236cb923e4b47f.tar.bz2
rails-e6ca7e7197f46df0e538f50cea236cb923e4b47f.zip
refactoring to remove crazy logic
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/relation/calculations.rb6
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb9
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