diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-09-22 21:43:48 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-09-22 21:43:48 -0700 |
commit | 08d034a89659f680438092c3eee29baead2e2d83 (patch) | |
tree | 14200d7a8835e36f686cbaba590a3e4ae5aaa2f0 | |
parent | e032dabdb2adb34e3db8cd35e9f58bc0536475c1 (diff) | |
parent | c001fadd2f2f420267db809439581e388684e9de (diff) | |
download | rails-08d034a89659f680438092c3eee29baead2e2d83.tar.gz rails-08d034a89659f680438092c3eee29baead2e2d83.tar.bz2 rails-08d034a89659f680438092c3eee29baead2e2d83.zip |
Merge pull request #142 from sunaku/subquery
to_sql: add support for emitting SQL subqueries
-rw-r--r-- | lib/arel/visitors/to_sql.rb | 4 | ||||
-rw-r--r-- | test/visitors/test_to_sql.rb | 5 |
2 files changed, 9 insertions, 0 deletions
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index a350daa3da..f5be934ba5 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -254,6 +254,10 @@ key on UpdateManager using UpdateManager#key= "(#{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 diff --git a/test/visitors/test_to_sql.rb b/test/visitors/test_to_sql.rb index 1caedacd45..064f14739c 100644 --- a/test/visitors/test_to_sql.rb +++ b/test/visitors/test_to_sql.rb @@ -126,6 +126,11 @@ module Arel @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 %{ |