-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix member association filtering #48
base: master
Are you sure you want to change the base?
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_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 thetype
column, but only if STI is detected.