diff options
-rw-r--r-- | lib/arel/select_manager.rb | 2 | ||||
-rw-r--r-- | lib/arel/table.rb | 21 | ||||
-rw-r--r-- | spec/select_manager_spec.rb | 5 | ||||
-rw-r--r-- | spec/table_spec.rb | 7 |
4 files changed, 24 insertions, 11 deletions
diff --git a/lib/arel/select_manager.rb b/lib/arel/select_manager.rb index 77930a6bb1..adbf1316d7 100644 --- a/lib/arel/select_manager.rb +++ b/lib/arel/select_manager.rb @@ -128,6 +128,8 @@ module Arel end def join_sql + return nil unless @ctx.froms + viz = Visitors::JoinSql.new @engine Nodes::SqlLiteral.new viz.accept @ctx end diff --git a/lib/arel/table.rb b/lib/arel/table.rb index e71d7d392c..171d165bc2 100644 --- a/lib/arel/table.rb +++ b/lib/arel/table.rb @@ -49,40 +49,39 @@ module Arel end def join relation, klass = Nodes::InnerJoin - return select_manager unless relation + return from(self) unless relation - sm = SelectManager.new(@engine) case relation when String, Nodes::SqlLiteral raise if relation.blank? - sm.from Nodes::StringJoin.new(self, relation) + from Nodes::StringJoin.new(self, relation) else - sm.from klass.new(self, relation, nil) + from klass.new(self, relation, nil) end end def group *columns - select_manager.group(*columns) + from(self).group(*columns) end def order *expr - select_manager.order(*expr) + from(self).order(*expr) end def where condition - select_manager.where condition + from(self).where condition end def project *things - select_manager.project(*things) + from(self).project(*things) end def take amount - select_manager.take amount + from(self).take amount end def having expr - select_manager.having expr + from(self).having expr end def columns @@ -98,7 +97,7 @@ module Arel end def select_manager - SelectManager.new(@engine, self) + SelectManager.new(@engine) end private diff --git a/spec/select_manager_spec.rb b/spec/select_manager_spec.rb index e5b65b4698..287657d0c1 100644 --- a/spec/select_manager_spec.rb +++ b/spec/select_manager_spec.rb @@ -299,6 +299,11 @@ module Arel manager.join_sql.should be_like %{ 'hello' } check manager.joins(manager).should == manager.join_sql end + + it 'returns nil join sql' do + manager = Arel::SelectManager.new Table.engine + manager.join_sql.should be_nil + end end describe 'order_clauses' do diff --git a/spec/table_spec.rb b/spec/table_spec.rb index 15f2e024e0..d0ba46ae56 100644 --- a/spec/table_spec.rb +++ b/spec/table_spec.rb @@ -12,6 +12,13 @@ module Arel end end + describe 'select_manager' do + it 'should return an empty select manager' do + sm = @relation.select_manager + sm.to_sql.should be_like 'SELECT' + end + end + describe 'having' do it 'adds a having clause' do mgr = @relation.having @relation[:id].eq(10) |