Conversation
When defining an association through a join table to a model using single table inheritance, ActiveRecord will always store the base class name in the join table. This allows the base class to always be correctly queried, but makes it challenging to correctly define an association that only returns a subclass. Groupify groups define member associations using the `source_type` set correctly to the base class, but this returns all members of the base class instead of filtering to only members of the subclass. This fixes the issue by adding a filtering condition to the association on the `type` column, but only if STI is detected.
|
Fixes issue reported in #47. |
|
I'll need to do some more research on how to accomplish this in Mongoid before this can be released. |
|
Mongoid You could hack around by not creating a new has_many but using the Something like Alternatively |
|
I would be okay with having documented differences between Mongoid and ActiveRecord. It probably isn't possible to maintain 100% feature parity, but they can retain the 99% the same basic interface. The Readme should also be more insistent that consumers stick to the public interface and not rely too much on the internal implementation details. |
|
Yes I agree. This fix won't be necessary once the |
When defining an association through a join table to a model using single table inheritance, ActiveRecord will always store the base class name in the join table. This allows the base class to always be correctly queried, but makes it challenging to correctly define an association that only returns a subclass.
Groupify groups define member associations using the
source_typeset correctly to the base class, but this returns all members of the base class instead of filtering to only members of the subclass. This fixes the issue by adding a filtering condition to the association on thetypecolumn, but only if STI is detected.