Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

to_sql: add support for emitting SQL subqueries #142

Merged
merged 1 commit into from

2 participants

@sunaku

Added support for running #to_sql() on an Arel query tree that contains nested subqueries (Arel::SelectManager), which themselves may contain nested subqueries, ad infinitum. :cake:

@tenderlove tenderlove merged commit 08d034a into from
@sunaku

Thanks for merging this pull @tenderlove !

Would you kindly merge these pulls too? :bowtie:

  • #140 bugfix - some aggregations lacked DISTINCT emission
  • #141 feature - add Arel::SelectManager#projections method

Thanks for your consideration.

@sunaku

Hooray! They're all merged. Arigatou @tenderlove ! :sparkles:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 22, 2012
  1. @sunaku
This page is out of date. Refresh to see the latest.
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 %{
Something went wrong with that request. Please try again.