diff options
-rw-r--r-- | lib/arel/nodes.rb | 2 | ||||
-rw-r--r-- | test/attributes/test_attribute.rb | 11 |
2 files changed, 12 insertions, 1 deletions
diff --git a/lib/arel/nodes.rb b/lib/arel/nodes.rb index a68e327983..59cfc04dc2 100644 --- a/lib/arel/nodes.rb +++ b/lib/arel/nodes.rb @@ -78,7 +78,7 @@ module Arel 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::Nodes::SelectStatement, Arel::Table, Arel::Nodes::BindParam, Arel::SelectManager other else case attribute diff --git a/test/attributes/test_attribute.rb b/test/attributes/test_attribute.rb index 145da98968..38ee189a46 100644 --- a/test/attributes/test_attribute.rb +++ b/test/attributes/test_attribute.rb @@ -74,6 +74,17 @@ module Arel 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 |