diff options
author | Bryan Helmkamp <bryan@brynary.com> | 2009-05-17 14:49:56 -0400 |
---|---|---|
committer | Bryan Helmkamp <bryan@brynary.com> | 2009-05-17 14:49:56 -0400 |
commit | 3a6e8e5a3f99841691b70b89b0a10f836e6ec071 (patch) | |
tree | 89e59775b729616ca9cb4a4f1f70415af35ce3d7 /lib/arel/algebra | |
parent | 892337509b2bd269920dc567bc48c6a28c7222d2 (diff) | |
download | rails-3a6e8e5a3f99841691b70b89b0a10f836e6ec071.tar.gz rails-3a6e8e5a3f99841691b70b89b0a10f836e6ec071.tar.bz2 rails-3a6e8e5a3f99841691b70b89b0a10f836e6ec071.zip |
join sql stuff moved into sql adapter
Conflicts:
lib/arel/algebra/primitives/value.rb
lib/arel/algebra/relations/operations/join.rb
lib/arel/algebra/relations/relation.rb
spec/arel/unit/relations/join_spec.rb
Diffstat (limited to 'lib/arel/algebra')
-rw-r--r-- | lib/arel/algebra/primitives/value.rb | 1 | ||||
-rw-r--r-- | lib/arel/algebra/relations/operations/join.rb | 14 | ||||
-rw-r--r-- | lib/arel/algebra/relations/relation.rb | 15 | ||||
-rw-r--r-- | lib/arel/algebra/relations/utilities/compound.rb | 3 |
4 files changed, 19 insertions, 14 deletions
diff --git a/lib/arel/algebra/primitives/value.rb b/lib/arel/algebra/primitives/value.rb index 91c4045507..76c82890d0 100644 --- a/lib/arel/algebra/primitives/value.rb +++ b/lib/arel/algebra/primitives/value.rb @@ -2,7 +2,6 @@ module Arel class Value attributes :value, :relation deriving :initialize, :== - delegate :inclusion_predicate_sql, :equality_predicate_sql, :to => :value def bind(relation) Value.new(value, relation) diff --git a/lib/arel/algebra/relations/operations/join.rb b/lib/arel/algebra/relations/operations/join.rb index 8e19254378..695f360b51 100644 --- a/lib/arel/algebra/relations/operations/join.rb +++ b/lib/arel/algebra/relations/operations/join.rb @@ -1,12 +1,12 @@ module Arel class Join < Relation - attributes :join_sql, :relation1, :relation2, :predicates + attributes :relation1, :relation2, :predicates deriving :== delegate :engine, :name, :to => :relation1 hash_on :relation1 - def initialize(join_sql, relation1, relation2 = Nil.instance, *predicates) - @join_sql, @relation1, @relation2, @predicates = join_sql, relation1, relation2, predicates + def initialize(relation1, relation2 = Nil.instance, *predicates) + @relation1, @relation2, @predicates = relation1, relation2, predicates end def attributes @@ -33,6 +33,14 @@ module Arel end end + class InnerJoin < Join; end + class OuterJoin < Join; end + class StringJoin < Join + def attributes + relation1.externalize.attributes + end + end + class Relation def join? false diff --git a/lib/arel/algebra/relations/relation.rb b/lib/arel/algebra/relations/relation.rb index 20badaf165..6d76e66638 100644 --- a/lib/arel/algebra/relations/relation.rb +++ b/lib/arel/algebra/relations/relation.rb @@ -32,28 +32,27 @@ module Arel include Enumerable module Operable - def join(other_relation = nil, join_type = "INNER JOIN") + def join(other_relation = nil, join_class = InnerJoin) case other_relation when String - Join.new(other_relation, self) + StringJoin.new(other_relation, self) when Relation - JoinOperation.new(join_type, self, other_relation) + JoinOperation.new(join_class, self, other_relation) else self end end def outer_join(other_relation = nil) - join(other_relation, "LEFT OUTER JOIN") + join(other_relation, OuterJoin) end [:where, :project, :order, :take, :skip, :group].each do |operation_name| - operation = <<-OPERATION + class_eval <<-OPERATION, __FILE__, __LINE__ def #{operation_name}(*arguments, &block) arguments.all?(&:blank?) && !block_given?? self : #{operation_name.to_s.classify}.new(self, *arguments, &block) end OPERATION - class_eval operation, __FILE__, __LINE__ end def alias @@ -75,9 +74,9 @@ module Arel end include Writable - JoinOperation = Struct.new(:join_sql, :relation1, :relation2) do + JoinOperation = Struct.new(:join_class, :relation1, :relation2) do def on(*predicates) - Join.new(join_sql, relation1, relation2, *predicates) + join_class.new(relation1, relation2, *predicates) end end end diff --git a/lib/arel/algebra/relations/utilities/compound.rb b/lib/arel/algebra/relations/utilities/compound.rb index e33b8dbf14..fbff36a868 100644 --- a/lib/arel/algebra/relations/utilities/compound.rb +++ b/lib/arel/algebra/relations/utilities/compound.rb @@ -7,12 +7,11 @@ module Arel :to => :relation [:attributes, :wheres, :groupings, :orders].each do |operation_name| - operation = <<-OPERATION + class_eval <<-OPERATION, __FILE__, __LINE__ def #{operation_name} @#{operation_name} ||= relation.#{operation_name}.collect { |o| o.bind(self) } end OPERATION - class_eval operation, __FILE__, __LINE__ end end end |