aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/algebra
diff options
context:
space:
mode:
Diffstat (limited to 'lib/arel/algebra')
-rw-r--r--lib/arel/algebra/relations/operations/join.rb30
1 files changed, 28 insertions, 2 deletions
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