Skip to content

Commit

Permalink
supporting any node in SelectManager#from
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Mar 24, 2011
1 parent b707ddd commit 2b27e65
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/arel/select_manager.rb
Expand Up @@ -38,6 +38,10 @@ def exists
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"
Expand Down Expand Up @@ -86,10 +90,10 @@ def from table
# 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
Expand Down
17 changes: 17 additions & 0 deletions test/test_select_manager.rb
Expand Up @@ -101,6 +101,23 @@ def test_join_sources
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
Expand Down

0 comments on commit 2b27e65

Please sign in to comment.