Skip to content

Commit

Permalink
Merge pull request rails#142 from sunaku/subquery
Browse files Browse the repository at this point in the history
to_sql: add support for emitting SQL subqueries
  • Loading branch information
tenderlove committed Sep 23, 2012
2 parents e032dab + c001fad commit 08d034a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/arel/visitors/to_sql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions test/visitors/test_to_sql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %{
Expand Down

0 comments on commit 08d034a

Please sign in to comment.