diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-07-26 14:59:46 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-07-26 14:59:46 -0700 |
commit | d41b9c54aaafb852ff2e4fbba56962cb3eeb1837 (patch) | |
tree | a8f3bdac6ad56be06727056cde7c94ef22065ef5 | |
parent | 66cedcc76bf8ac97a65bf12f6b7dd2eea83ebfe3 (diff) | |
download | rails-d41b9c54aaafb852ff2e4fbba56962cb3eeb1837.tar.gz rails-d41b9c54aaafb852ff2e4fbba56962cb3eeb1837.tar.bz2 rails-d41b9c54aaafb852ff2e4fbba56962cb3eeb1837.zip |
more class reorganization
-rw-r--r-- | lib/arel/algebra/relations/operations/join.rb | 30 | ||||
-rw-r--r-- | lib/arel/engines/sql/relations.rb | 1 | ||||
-rw-r--r-- | lib/arel/engines/sql/relations/operations/join.rb | 33 | ||||
-rw-r--r-- | lib/arel/recursion/base_case.rb | 13 |
4 files changed, 41 insertions, 36 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 diff --git a/lib/arel/engines/sql/relations.rb b/lib/arel/engines/sql/relations.rb index c29739ef7f..c692683421 100644 --- a/lib/arel/engines/sql/relations.rb +++ b/lib/arel/engines/sql/relations.rb @@ -2,4 +2,3 @@ require 'arel/engines/sql/relations/utilities/compound' require 'arel/engines/sql/relations/utilities/nil' require 'arel/engines/sql/relations/compiler' require 'arel/engines/sql/relations/table' -require 'arel/engines/sql/relations/operations/join' diff --git a/lib/arel/engines/sql/relations/operations/join.rb b/lib/arel/engines/sql/relations/operations/join.rb deleted file mode 100644 index 9733657365..0000000000 --- a/lib/arel/engines/sql/relations/operations/join.rb +++ /dev/null @@ -1,33 +0,0 @@ -module Arel - class Join - 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 - 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 - end -end diff --git a/lib/arel/recursion/base_case.rb b/lib/arel/recursion/base_case.rb new file mode 100644 index 0000000000..84a526f57c --- /dev/null +++ b/lib/arel/recursion/base_case.rb @@ -0,0 +1,13 @@ +module Arel + module Recursion + module BaseCase + def table + self + end + + def table_sql(formatter = Sql::TableReference.new(self)) + formatter.table self + end + end + end +end |