Skip to content

Commit

Permalink
Merge pull request #290 from mekishizufu/fix_select_manager_as_subquery
Browse files Browse the repository at this point in the history
Support passing of SelectManager to attribute methods
  • Loading branch information
rafaelfranca committed Jun 13, 2014
2 parents 282bb10 + 99d6646 commit 9ea4d46
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/arel/nodes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Quoted < Arel::Nodes::Unary # :nodoc:

def self.build_quoted other, attribute = nil
case other
when Arel::Nodes::Node, Arel::Attributes::Attribute, Arel::Nodes::SelectStatement, Arel::Table, Arel::Nodes::BindParam
when Arel::Nodes::Node, Arel::Attributes::Attribute, Arel::Table, Arel::Nodes::BindParam, Arel::SelectManager
other
else
case attribute
Expand Down
11 changes: 11 additions & 0 deletions test/attributes/test_attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ module Attributes
SELECT "users"."id" FROM "users" WHERE "users"."id" > 10
}
end

it 'should handle comparing with a subquery' do
users = Table.new(:users)

avg = users.project(users[:karma].average)
mgr = users.project(Arel.star).where(users[:karma].gt(avg))

mgr.to_sql.must_be_like %{
SELECT * FROM "users" WHERE "users"."karma" > (SELECT AVG("users"."karma") AS avg_id FROM "users")
}
end
end

describe '#gt_any' do
Expand Down

0 comments on commit 9ea4d46

Please sign in to comment.