#424 ✓not-applicable
Ben Erickson

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

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

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
    book.library_id.should == lib.id
  it "should inherit parents associations" do
    lib = Library.new(:name => "lib")
    fiction = Fiction.new(:title => "fiction", :isbn => "3456")
    lib.books << fiction
    fiction.library_id.should == lib.id

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

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) December 4th, 2008 @ 02:37 AM

    • State changed from “new” to “not-applicable”
    • Assigned user cleared.

    Attached is a script that duplicates the failing code in the above example, but it shows as passing with the latest stable gems.

    Marking this ticket as not-applicable.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket