1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

join relation qualification

This commit is contained in:
Nick Kallen 2008-01-05 15:32:22 -08:00
parent d7b89d957d
commit d1e5265a1d
8 changed files with 19 additions and 12 deletions

View file

@ -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

View file

@ -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

View file

@ -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])

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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