diff options
-rw-r--r-- | lib/arel/select_manager.rb | 8 | ||||
-rw-r--r-- | test/test_select_manager.rb | 17 |
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 |