From d41b9c54aaafb852ff2e4fbba56962cb3eeb1837 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 26 Jul 2010 14:59:46 -0700 Subject: more class reorganization --- lib/arel/algebra/relations/operations/join.rb | 30 +++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'lib/arel/algebra') diff --git a/lib/arel/algebra/relations/operations/join.rb b/lib/arel/algebra/relations/operations/join.rb index 5d19873f62..83ebfc129f 100644 --- a/lib/arel/algebra/relations/operations/join.rb +++ b/lib/arel/algebra/relations/operations/join.rb @@ -44,6 +44,22 @@ module Arel relation1.engine != relation2.engine ? Memory::Engine.new : relation1.engine end + def table_sql(formatter = Sql::TableReference.new(self)) + relation1.externalize.table_sql(formatter) + end + + def joins(environment, formatter = Sql::TableReference.new(environment)) + @joins ||= begin + this_join = [ + join_sql, + relation2.externalize.table_sql(formatter), + ("ON" unless predicates.blank?), + (ons + relation2.externalize.wheres).collect { |p| p.bind(environment.relation).to_sql(Sql::WhereClause.new(environment)) }.join(' AND ') + ].compact.join(" ") + [relation1.joins(environment), this_join, relation2.joins(environment)].compact.join(" ") + end + end + def == other super || Join === other && relation1 == other.relation1 && @@ -68,9 +84,19 @@ module Arel end end - class InnerJoin < Join; end - class OuterJoin < Join; end + class InnerJoin < Join + def join_sql; "INNER JOIN" end + end + + class OuterJoin < Join + def join_sql; "LEFT OUTER JOIN" end + end + class StringJoin < Join + def joins(environment, formatter = Sql::TableReference.new(environment)) + [relation1.joins(environment), relation2].compact.join(" ") + end + def externalizable? relation1.externalizable? end -- cgit v1.2.3