This repository has been archived by the owner on Apr 17, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure m:m joins join with the FK of the inner association properly
[#903 state:resolved]
- Loading branch information
Showing
2 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
spec/public/associations/many_to_many/read_multiple_join_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper')) | ||
|
||
describe 'Many to Many Associations read across multiple join associations' do | ||
before :all do | ||
class User | ||
include DataMapper::Resource | ||
|
||
property :id, Serial | ||
|
||
has n, :sales | ||
has n, :sale_items, :through => :sales | ||
has n, :items, :through => :sale_items | ||
end | ||
|
||
class Sale | ||
include DataMapper::Resource | ||
|
||
property :id, Serial | ||
|
||
belongs_to :user | ||
has n, :sale_items | ||
has n, :items, :through => :sale_items | ||
end | ||
|
||
class SaleItem | ||
include DataMapper::Resource | ||
|
||
property :id, Serial | ||
|
||
belongs_to :sale | ||
belongs_to :item | ||
end | ||
|
||
class Item | ||
include DataMapper::Resource | ||
|
||
property :id, Serial | ||
|
||
has n, :sale_items | ||
end | ||
end | ||
|
||
supported_by :all do | ||
before :all do | ||
@user = User.create | ||
@sale = @user.sales.create | ||
|
||
5.times { @sale.items.create } | ||
end | ||
|
||
before :all do | ||
@no_join = defined?(DataMapper::Adapters::InMemoryAdapter) && @adapter.kind_of?(DataMapper::Adapters::InMemoryAdapter) || | ||
defined?(DataMapper::Adapters::YamlAdapter) && @adapter.kind_of?(DataMapper::Adapters::YamlAdapter) | ||
|
||
@skip = @no_join | ||
end | ||
|
||
before do | ||
pending if @skip | ||
end | ||
|
||
it 'should return all the created entries' do | ||
@user.items.to_a.should == Item.all.to_a | ||
@sale.items.to_a.should == Item.all.to_a | ||
end | ||
end | ||
end |
f7aef8a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rock!
f7aef8a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sweet, i think this was a problem i had a week or so ago