STI / Polymorphic Association Issue (or possible bug)?

Hey everyone,

I have been working on some code lately that seems to be yielding some unexpected results. Basically, I have a class that is using single table inheritance for basic subclassing, and I wanted the base class to be able to use a polymorphic interface for connecting up the different classes of information generically using one table.

here is a pastie of the example: Parked at Loopia

Am I doing something wrong? Is this a bug? looking for advice.


* Derek P. <> [2008-06-02 19:07:33 -0700]:

here is a pastie of the example: Parked at Loopia

You should put the has_many in SubPost

Hey Xie,

Actually, it doesn't matter where the has_many lives. Due to inheritance, it is actually defined for both classes. I spoke with bitsweat on IRC about this behavior and it turns out its expected, and here is why:

All STI-based interactions with polymorphic objects will refer to the base class of the STI, by design. But, if you actually load that object into memory and check its class, you'll see that its actually lazy-loaded (via the classable_id) and becomes the proper class at runtime. Now, I don't *love* this design, and frankly, it will make it much harder to deal with as far as filtering is concerned, but hey, at least it works.

Thanks for the help though.

- Derek