Permalink
Browse files

cleaning up confusing logic

  • Loading branch information...
1 parent 7020c92 commit bd1059f5adf60d6e302759f098daa9c2910e62d7 @tenderlove tenderlove committed Sep 7, 2010
Showing with 6 additions and 3 deletions.
  1. +6 −3 activerecord/lib/active_record/relation/query_methods.rb
@@ -274,10 +274,13 @@ def build_select(arel, selects)
@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
- if selects.all? {|s| s.is_a?(String) || !s.is_a?(Arel::Expression) } && !(selects.last =~ /^COUNT\(/)
- arel.project(*selects)
+ case select = selects.last
+ when Arel::Expression, Arel::SqlLiteral
+ arel.project(select)
+ when /^COUNT\(/
+ arel.project(Arel::SqlLiteral.new(select))
else
- arel.project(selects.last)
+ arel.project(*selects)
end
else
arel.project(Arel::SqlLiteral.new(@klass.quoted_table_name + '.*'))

0 comments on commit bd1059f

Please sign in to comment.