STI [grand]child associations
Reported by Ben Erickson | June 27th, 2008 @ 09:52 PM
This bug is based on the assumption that STI children, etc should inherit the associations of their parents. I tried out a spec using sti_spec in dm-core. Ill paste the altered/new code below.
I added the class
class Library
include DataMapper::Resource
property :id, Serial
property :name, String
has n, :books
end
and modified Books with the additional association
class Book
include DataMapper::Resource
property :id, Serial
property :title, String, :nullable => false
property :isbn, Integer, :nullable => false
property :class_type, Discriminator
belongs_to :library
end
and then tried the following spec
describe "with associations" do
it "should belong to library" do
lib = Library.new(:name => "lib")
book = Book.new(:title => "book", :isbn => "1234")
lib.books << book
lib.save
#passes
book.library_id.should == lib.id
end
it "should inherit parents associations" do
lib = Library.new(:name => "lib")
fiction = Fiction.new(:title => "fiction", :isbn => "3456")
lib.books << fiction
lib.save
#fails
fiction.library_id.should == lib.id
end
end
If my assumption is incorrect, I'd appreciate a little guidance as to what I'm doing incorrectly. Thanks guys. Keep up the good work.
Comments and changes to this ticket
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
