Skip to content
This repository
Browse code

to_sql: add support for emitting SQL subqueries

  • Loading branch information...
commit c001fadd2f2f420267db809439581e388684e9de 1 parent e032dab
Suraj N. Kurapati sunaku authored
4 lib/arel/visitors/to_sql.rb
@@ -254,6 +254,10 @@ def visit_Arel_Nodes_Grouping o
254 254 "(#{visit o.expr})"
255 255 end
256 256
  257 + def visit_Arel_SelectManager o
  258 + "(#{o.to_sql.rstrip})"
  259 + end
  260 +
257 261 def visit_Arel_Nodes_Ascending o
258 262 "#{visit o.expr} ASC"
259 263 end
5 test/visitors/test_to_sql.rb
@@ -126,6 +126,11 @@ def dispatch
126 126 @visitor.accept(nil).must_be_like "NULL"
127 127 end
128 128
  129 + it "should visit_Arel_SelectManager, which is a subquery" do
  130 + mgr = Table.new(:foo).project(:bar)
  131 + @visitor.accept(mgr).must_be_like '(SELECT bar FROM "foo")'
  132 + end
  133 +
129 134 it "should visit_Arel_Nodes_And" do
130 135 node = Nodes::And.new [@attr.eq(10), @attr.eq(11)]
131 136 @visitor.accept(node).must_be_like %{

0 comments on commit c001fad

Please sign in to comment.
Something went wrong with that request. Please try again.