aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/algebra/relations/operations/join.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/arel/algebra/relations/operations/join.rb')
-rw-r--r--lib/arel/algebra/relations/operations/join.rb64
1 files changed, 64 insertions, 0 deletions
diff --git a/lib/arel/algebra/relations/operations/join.rb b/lib/arel/algebra/relations/operations/join.rb
new file mode 100644
index 0000000000..e9320f28e1
--- /dev/null
+++ b/lib/arel/algebra/relations/operations/join.rb
@@ -0,0 +1,64 @@
+module Arel
+ class Join < Relation
+ attributes :relation1, :relation2, :predicates
+ deriving :==
+ delegate :name, :to => :relation1
+
+ def initialize(relation1, relation2 = Nil.instance, *predicates)
+ @relation1, @relation2, @predicates = relation1, relation2, predicates
+ end
+
+ def hash
+ @hash ||= :relation1.hash
+ end
+
+ def eql?(other)
+ self == other
+ end
+
+ def attributes
+ @attributes ||= (relation1.externalize.attributes +
+ relation2.externalize.attributes).collect { |a| a.bind(self) }
+ end
+
+ def wheres
+ # TESTME bind to self?
+ relation1.externalize.wheres
+ end
+
+ def ons
+ @ons ||= @predicates.collect { |p| p.bind(self) }
+ end
+
+ # TESTME
+ def externalizable?
+ relation1.externalizable? or relation2.externalizable?
+ end
+
+ def join?
+ true
+ end
+
+ def engine
+ relation1.engine != relation2.engine ? Memory::Engine.new : relation1.engine
+ end
+ end
+
+ class InnerJoin < Join; end
+ class OuterJoin < Join; end
+ class StringJoin < Join
+ def attributes
+ relation1.externalize.attributes
+ end
+
+ def engine
+ relation1.engine
+ end
+ end
+
+ class Relation
+ def join?
+ false
+ end
+ end
+end