Browse files

Merge pull request #142 from sunaku/subquery

to_sql: add support for emitting SQL subqueries
  • Loading branch information...
2 parents e032dab + c001fad commit 08d034a89659f680438092c3eee29baead2e2d83 @tenderlove tenderlove committed Sep 22, 2012
Showing with 9 additions and 0 deletions.
  1. +4 −0 lib/arel/visitors/to_sql.rb
  2. +5 −0 test/visitors/test_to_sql.rb
View
4 lib/arel/visitors/to_sql.rb
@@ -254,6 +254,10 @@ def visit_Arel_Nodes_Grouping o
"(#{visit o.expr})"
end
+ def visit_Arel_SelectManager o
+ "(#{o.to_sql.rstrip})"
+ end
+
def visit_Arel_Nodes_Ascending o
"#{visit o.expr} ASC"
end
View
5 test/visitors/test_to_sql.rb
@@ -126,6 +126,11 @@ def dispatch
@visitor.accept(nil).must_be_like "NULL"
end
+ it "should visit_Arel_SelectManager, which is a subquery" do
+ mgr = Table.new(:foo).project(:bar)
+ @visitor.accept(mgr).must_be_like '(SELECT bar FROM "foo")'
+ end
+
it "should visit_Arel_Nodes_And" do
node = Nodes::And.new [@attr.eq(10), @attr.eq(11)]
@visitor.accept(node).must_be_like %{

0 comments on commit 08d034a

Please sign in to comment.