Repository navigation
Run the internal reads of BelongsToManyRelation writes without find hooks (#2667) - #347
Merged
Merged
Conversation
lehni
force-pushed
the
fix/rc-bm-find-hooks
branch
2 times, most recently
from
October 12, 2026 21:02
20afa1c to
6fa6364
Compare
lehni
force-pushed
the
fix/rc-bm-find-hooks
branch
from
October 12, 2026 21:19
6fa6364 to
2bc9e41
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The reads that
relate(),unrelate(),insert()anddelete()through aBelongsToManyRelationrun to keep the arrays of keys up to date (findKeys()andupdateKeys()) usefindOptions({ dontCallFindHooks: true }).dontCallFindHooksnow also skips the staticbeforeFindhook, not onlyafterFindand$afterFind(), so these reads call no find hooks at all. The writes still call the owner's update hooks.Why
These reads are no finds of the user, but they called the user's static
beforeFindandafterFindwith partial models and the relation's hook arguments, and used whatafterFindreturned as their data. AnafterFindthat filters rows, e.g. for soft deletes or access control, maderelate()resolve to 0 without writing anything.Breaking
dontCallFindHooksis internal. The other queries that use it,fetchGraph()/$fetchGraph()on the models it's given and the relations thatskipFetchedskips, no longer call the staticbeforeFindof these models. They already didn't callafterFind: the find hooks are only called for queries that run. The changelog lists it under Breaking changes next to the outerupsertGraph()queries, and the static hooks section of the migration guide says so.Tests
relate(), unrelate(), insert() and delete() should not call the find hookswithbeforeFindand filteringafterFindhooks on the owner and related model classes.should not call the find hooks of the root class in fetchGraph()also checksbeforeFind.Both fail without the change.
Part of #53.