Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

to_sql: add support for emitting SQL subqueries

  • Loading branch information...
commit c001fadd2f2f420267db809439581e388684e9de 1 parent e032dab
Suraj N. Kurapati sunaku authored
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
4 lib/arel/visitors/to_sql.rb
View
@@ -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
5 test/visitors/test_to_sql.rb
View
@@ -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 %{
Please sign in to comment.
Something went wrong with that request. Please try again.