aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/engines/sql/relations/operations/join.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/arel/engines/sql/relations/operations/join.rb')
-rw-r--r--lib/arel/engines/sql/relations/operations/join.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/arel/engines/sql/relations/operations/join.rb b/lib/arel/engines/sql/relations/operations/join.rb
new file mode 100644
index 0000000000..7c5e13510a
--- /dev/null
+++ b/lib/arel/engines/sql/relations/operations/join.rb
@@ -0,0 +1,33 @@
+module Arel
+ class Join < Relation
+ 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).to_sql(Sql::WhereClause.new(environment)) }.join(' AND ')
+ ].compact.join(" ")
+ [relation1.joins(environment), this_join, relation2.joins(environment)].compact.join(" ")
+ end
+ end
+ 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(_, __ = nil)
+ relation2
+ end
+ end
+end