diff --git a/lib/sql_algebra/relations/join_relation.rb b/lib/sql_algebra/relations/join_relation.rb index c65b07225f..6dd63ad117 100644 --- a/lib/sql_algebra/relations/join_relation.rb +++ b/lib/sql_algebra/relations/join_relation.rb @@ -10,7 +10,12 @@ class JoinRelation < Relation ((relation1 == other.relation1 and relation2 == other.relation2) or (relation2 == other.relation1 and relation1 == other.relation2)) end + + def qualify + JoinRelation.new(relation1.qualify, relation2.qualify, *predicates.collect(&:qualify)) + end + protected def joins relation1.joins + relation2.joins + [Join.new(relation1, relation2, predicates, join_type)] end @@ -27,6 +32,5 @@ class JoinRelation < Relation relation1[name] || relation2[name] end - protected delegate :table, :to => :relation1 end \ No newline at end of file diff --git a/spec/predicates/binary_predicate_spec.rb b/spec/predicates/binary_predicate_spec.rb index 25cffde2c5..ede44e5175 100644 --- a/spec/predicates/binary_predicate_spec.rb +++ b/spec/predicates/binary_predicate_spec.rb @@ -32,7 +32,7 @@ describe BinaryPredicate do end describe '#qualify' do - it "manufactures an equality predicate with qualified attributes" do + it "distributes over the predicates and attributes" do ConcreteBinaryPredicate.new(@attribute1, @attribute2).qualify. \ should == ConcreteBinaryPredicate.new(@attribute1.qualify, @attribute2.qualify) end diff --git a/spec/relations/join_relation_spec.rb b/spec/relations/join_relation_spec.rb index bae294440e..b7357b02e8 100644 --- a/spec/relations/join_relation_spec.rb +++ b/spec/relations/join_relation_spec.rb @@ -1,6 +1,6 @@ require File.join(File.dirname(__FILE__), '..', 'spec_helper') -describe 'between two relations' do +describe JoinRelation do before do @relation1 = TableRelation.new(:foo) @relation2 = TableRelation.new(:bar) @@ -18,6 +18,13 @@ describe 'between two relations' do end end + describe '#qualify' do + it 'distributes over the relations and predicates' do + JoinRelation.new(@relation1, @relation2, @predicate).qualify. \ + should == JoinRelation.new(@relation1.qualify, @relation2.qualify, @predicate.qualify) + end + end + describe '#to_sql' do before do @relation1 = @relation1.select(@relation1[:id] == @relation2[:foo_id]) diff --git a/spec/relations/order_relation_spec.rb b/spec/relations/order_relation_spec.rb index 62275ff0ac..8792683eec 100644 --- a/spec/relations/order_relation_spec.rb +++ b/spec/relations/order_relation_spec.rb @@ -17,7 +17,7 @@ describe OrderRelation do end describe '#qualify' do - it "manufactures an order relation with qualified attributes and qualified relation" do + it "distributes over the relation and attributes" do OrderRelation.new(@relation1, @attribute1).qualify. \ should == OrderRelation.new(@relation1.qualify, @attribute1.qualify) end diff --git a/spec/relations/projection_relation_spec.rb b/spec/relations/projection_relation_spec.rb index eb74b5cedf..149669c5b2 100644 --- a/spec/relations/projection_relation_spec.rb +++ b/spec/relations/projection_relation_spec.rb @@ -17,7 +17,7 @@ describe ProjectionRelation do end describe '#qualify' do - it "manufactures a projection relation with qualified attributes and qualified relation" do + it "distributes over teh relation and attributes" do ProjectionRelation.new(@relation1, @attribute1).qualify. \ should == ProjectionRelation.new(@relation1.qualify, @attribute1.qualify) end diff --git a/spec/relations/range_relation_spec.rb b/spec/relations/range_relation_spec.rb index 261afcaf8e..947bf35120 100644 --- a/spec/relations/range_relation_spec.rb +++ b/spec/relations/range_relation_spec.rb @@ -17,7 +17,7 @@ describe RangeRelation do end describe '#qualify' do - it "manufactures a range relation with a qualified relation and a qualified range" do + it "distributes over the relation and attributes" do pending end end diff --git a/spec/relations/rename_relation_spec.rb b/spec/relations/rename_relation_spec.rb index e7792d146a..7db329ad7a 100644 --- a/spec/relations/rename_relation_spec.rb +++ b/spec/relations/rename_relation_spec.rb @@ -12,10 +12,6 @@ describe RenameRelation do should == RenameRelation.new(RenameRelation.new(@relation, @relation[:id] => :humpty), @relation[:name] => :dumpty) end - it "make this test less brittle wrt/ hash order" do - pending - end - it "raises an exception if the alias provided is already used" do pending end @@ -48,7 +44,7 @@ describe RenameRelation do end describe '#qualify' do - it "manufactures a rename relation with an identical attribute and alias, but with a qualified relation" do + it "distributes over the relation and renames" do RenameRelation.new(@relation, @relation[:id] => :schmid).qualify. \ should == RenameRelation.new(@relation.qualify, @relation[:id].qualify => :schmid) end diff --git a/spec/relations/selection_relation_spec.rb b/spec/relations/selection_relation_spec.rb index 395a3f7693..7ffb3b3676 100644 --- a/spec/relations/selection_relation_spec.rb +++ b/spec/relations/selection_relation_spec.rb @@ -27,7 +27,7 @@ describe SelectionRelation do end describe '#qualify' do - it "manufactures a selection relation with qualified predicates and qualified relation" do + it "distributes over the relation and predicates" do SelectionRelation.new(@relation1, @predicate1).qualify. \ should == SelectionRelation.new(@relation1.qualify, @predicate1.qualify) end