From 0ebb5bf6590b8ac62c53538ade7095676baec3d4 Mon Sep 17 00:00:00 2001 From: Neeraj Singh and Santiago Pastorino Date: Thu, 24 Jun 2010 22:52:15 -0300 Subject: Support for multiple selects added [#4841 state:committed] --- activerecord/lib/active_record/relation/query_methods.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'activerecord/lib/active_record/relation/query_methods.rb') diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 1e570a569b..4dbb30c777 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -213,13 +213,16 @@ module ActiveRecord def build_select(arel, selects) if selects.present? @implicit_readonly = false - selects.each do |s| - arel = arel.project(s) if s.present? + # 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 + if selects.all? { |s| s.is_a?(String) || !s.is_a?(Arel::Expression) } && !(selects.last =~ /^COUNT\(/) + arel.project(*selects) + else + arel.project(selects.last) end else - arel = arel.project(@klass.quoted_table_name + '.*') + arel.project(@klass.quoted_table_name + '.*') end - arel end def apply_modules(modules) -- cgit v1.2.3