-
Notifications
You must be signed in to change notification settings - Fork 52
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
Incomplete BelongsToMany eager loads #273
Comments
I have implemented an appropriate failing test case for this (hexus/analogue@17f6af1a), and will be working on a fix this week. I noticed all the existing tests for the I will open a PR if I arrive at a fix that I'm happy with, or something that I think can serve a starting point for yourself to solve it as you see fit. |
I managed to fix this in my fork in a way that I'm not happy with. Preventing caching of eager-loaded |
I fixed the above by allowing loaded entities to be cached, but keeping the prevention of |
Fixed incomplete BelongsToMany eager loads (#273)
Closing this since PR has been merged. @hexus thanks for your contribution! |
Cheers! 🎉 |
The
BelongsToMany
relationship doesn't eager load properly in 5.6.12.I haven't yet isolated when this issue was introduced, but I've figured out where and how it happens.
ResultBuilder::loadRelation()
will call$relation->match()
on the relation after applying an eager loading scopeBelongsToMany::match()
. from the above call, then starts by eagerly loading the needed entitiesResultBuilder::buildResultSet()
for the related entities, which keys the results by related primary key, but this is incorrect for a many-to-many relationshipThis means each related model will only be seen once amongst their parent entity, not across many parent entities like they should be.
By the time
BelongsToMany::match()
is building a dictionary for parent keys, it's operating on related results that are keyed by related key. Instead, every row should be present.The only way I can see to improve this, so far, would be introducing a result builder for many-to-many relationships.
The text was updated successfully, but these errors were encountered: