aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-03-23 17:55:03 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2011-03-23 17:55:03 -0700
commit2b27e653f7be7649f56b834543bcaf27e2b44c74 (patch)
treee6ab2e2c9432f9e5e5747bfaac640f27845404fe
parentb707dddd89a61b86570cbe3a5e923bb8e436c38d (diff)
downloadrails-2b27e653f7be7649f56b834543bcaf27e2b44c74.tar.gz
rails-2b27e653f7be7649f56b834543bcaf27e2b44c74.tar.bz2
rails-2b27e653f7be7649f56b834543bcaf27e2b44c74.zip
supporting any node in SelectManager#from
-rw-r--r--lib/arel/select_manager.rb8
-rw-r--r--test/test_select_manager.rb17
2 files changed, 23 insertions, 2 deletions
diff --git a/lib/arel/select_manager.rb b/lib/arel/select_manager.rb
index 7f533fa91b..34a86da68d 100644
--- a/lib/arel/select_manager.rb
+++ b/lib/arel/select_manager.rb
@@ -38,6 +38,10 @@ module Arel
Arel::Nodes::Exists.new @ast
end
+ def as node, expr
+ Arel::Nodes::As.new node, expr
+ end
+
def where_clauses
if $VERBOSE
warn "(#{caller.first}) where_clauses is deprecated and will be removed in arel 3.0.0 with no replacement"
@@ -86,10 +90,10 @@ module Arel
# from the AR tests.
case table
- when Nodes::SqlLiteral, Arel::Table
- @ctx.source.left = table
when Nodes::Join
@ctx.source.right << table
+ else
+ @ctx.source.left = table
end
self
diff --git a/test/test_select_manager.rb b/test/test_select_manager.rb
index 3eec73a1f0..799c9fe453 100644
--- a/test/test_select_manager.rb
+++ b/test/test_select_manager.rb
@@ -101,6 +101,23 @@ module Arel
manager.project table['id']
manager.to_sql.must_be_like 'SELECT "users"."id" FROM users'
end
+
+ it 'should support any ast' do
+ table = Table.new :users
+ manager1 = Arel::SelectManager.new Table.engine
+
+ manager2 = Arel::SelectManager.new Table.engine
+ manager2.project(Arel.sql('*'))
+ manager2.from table
+
+ manager1.project Arel.sql('lol')
+ as = manager2.as manager2.grouping(manager2.ast), Arel.sql('omg')
+ manager1.from as
+
+ manager1.to_sql.must_be_like %{
+ SELECT lol FROM (SELECT * FROM "users" ) AS omg
+ }
+ end
end
describe 'having' do