aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/algebra
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-07-26 14:59:46 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-07-26 14:59:46 -0700
commitd41b9c54aaafb852ff2e4fbba56962cb3eeb1837 (patch)
treea8f3bdac6ad56be06727056cde7c94ef22065ef5 /lib/arel/algebra
parent66cedcc76bf8ac97a65bf12f6b7dd2eea83ebfe3 (diff)
downloadrails-d41b9c54aaafb852ff2e4fbba56962cb3eeb1837.tar.gz
rails-d41b9c54aaafb852ff2e4fbba56962cb3eeb1837.tar.bz2
rails-d41b9c54aaafb852ff2e4fbba56962cb3eeb1837.zip
more class reorganization
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