Permalink
Browse files

to_sql: add support for emitting SQL subqueries

  • Loading branch information...
1 parent e032dab commit c001fadd2f2f420267db809439581e388684e9de @sunaku sunaku 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 c001fad

Please sign in to comment.