-
Notifications
You must be signed in to change notification settings - Fork 30
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
belongsToMany
associations are not respecting conditions
.
#135
Comments
Perhaps related: FriendsOfCake/crud#651 |
I've found a work-around for this, which is imho rather messy. I'd appreciate insight into whether this is actually how it should be done – maybe this is beyond the scope of The work-around requires much code. Firstly in the
Secondly in the
These will honour the association conditions, but only by restating the conditions, not being drawn from the association itself, which means it's not DRY. Pretty clunky :-/ |
Seems like there may be a way of using config instead to achieve something similar: https://crud.readthedocs.io/en/latest/listeners/related-models.html#configuring Although I haven't managed to get that to work. |
Took some thinking, and a bit of digging, but the issue is that your association conditions aren't correctly aliased. This means that the ORM doesn't know what or where those conditions should be applied, and so takes the safe route and doesn't apply them to |
Given a pivot table
EnquiryContacts
between tableEnquiriesTable
andPeopleTable
with the following conditional associations onEnquiriesTable
:and the corresponding reverse associations on
PeopleTable
:The
self
andrelated
links generated for these associations on thehttp://{{domain}}/api/enquiries/5
URL will contain the same set of results if followed – i.e. withoutconditions
differentiation.Thus for
related
URLs,http://{{domain}}/api/enquiries/5/relationships/clients
will show the same set of results as forhttp://{{domain}}/api/enquiries/5/relationships/administratives
and the same applies for theself
URLs.The text was updated successfully, but these errors were encountered: