From 502b43f00904967d9679b208a08beb764ce8911e Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 7 Sep 2010 14:49:06 -0700 Subject: joins are starting to work better --- lib/arel/table.rb | 4 ++-- spec/arel/table_spec.rb | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/arel/table.rb b/lib/arel/table.rb index 7811c217a7..434f19cc6b 100644 --- a/lib/arel/table.rb +++ b/lib/arel/table.rb @@ -30,14 +30,14 @@ module Arel nil end - def join relation + def join relation, klass = Nodes::InnerJoin sm = SelectManager.new(@engine) case relation when String, Nodes::SqlLiteral raise if relation.blank? sm.from Nodes::StringJoin.new(self, relation) else - sm.from Nodes::InnerJoin.new(self, relation, nil) + sm.from klass.new(self, relation, nil) end end diff --git a/spec/arel/table_spec.rb b/spec/arel/table_spec.rb index 2ea45dcca1..78705b4f0a 100644 --- a/spec/arel/table_spec.rb +++ b/spec/arel/table_spec.rb @@ -12,6 +12,20 @@ module Arel check @relation.joins(nil).should == nil end end + + describe 'join' do + it 'takes a second argument for join type' do + right = @relation.alias + predicate = @relation[:id].eq(right[:id]) + mgr = @relation.join(right, Nodes::OuterJoin).on(predicate) + + mgr.to_sql.should be_like %{ + SELECT FROM "users" + OUTER JOIN "users" "users_2" + ON "users"."id" = "users_2"."id" + } + end + end end describe 'alias' do -- cgit v1.2.3