diff options
author | Neeraj Singh and Santiago Pastorino <neeraj+santiago@wyeworks.com> | 2010-06-24 22:52:15 -0300 |
---|---|---|
committer | Santiago Pastorino <santiago@wyeworks.com> | 2010-06-25 15:57:04 -0300 |
commit | 0ebb5bf6590b8ac62c53538ade7095676baec3d4 (patch) | |
tree | d5cb0d2659f27faa00cdf9dc54c7247e042b954d /activerecord/lib/active_record | |
parent | 3d8ccb924084ecd341b2d9644e6e0b66903d8432 (diff) | |
download | rails-0ebb5bf6590b8ac62c53538ade7095676baec3d4.tar.gz rails-0ebb5bf6590b8ac62c53538ade7095676baec3d4.tar.bz2 rails-0ebb5bf6590b8ac62c53538ade7095676baec3d4.zip |
Support for multiple selects added
[#4841 state:committed]
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 11 |
1 files changed, 7 insertions, 4 deletions
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) |