Skip to content

Run the internal reads of BelongsToManyRelation writes without find hooks (#2667) - #347

Merged
lehni merged 1 commit into
nextfrom
fix/rc-bm-find-hooks
Oct 12, 2026
Merged

lehni merged 1 commit into
nextfrom
fix/rc-bm-find-hooks

Conversation

@lehni

@lehni lehni commented Oct 12, 2026 •

Copy link
Copy Markdown

What

The reads that relate(), unrelate(), insert() and delete() through a BelongsToManyRelation run to keep the arrays of keys up to date (findKeys() and updateKeys()) use findOptions({ dontCallFindHooks: true }). dontCallFindHooks now also skips the static beforeFind hook, not only afterFind and $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 beforeFind and afterFind with partial models and the relation's hook arguments, and used what afterFind returned as their data. An afterFind that filters rows, e.g. for soft deletes or access control, made relate() resolve to 0 without writing anything.

Breaking

dontCallFindHooks is internal. The other queries that use it, fetchGraph() / $fetchGraph() on the models it's given and the relations that skipFetched skips, no longer call the static beforeFind of these models. They already didn't call afterFind: the find hooks are only called for queries that run. The changelog lists it under Breaking changes next to the outer upsertGraph() queries, and the static hooks section of the migration guide says so.

Tests

  • relate(), unrelate(), insert() and delete() should not call the find hooks with beforeFind and filtering afterFind hooks on the owner and related model classes.
  • should not call the find hooks of the root class in fetchGraph() also checks beforeFind.

Both fail without the change.

Part of #53.

@lehni lehni added the 4.0 Breaking change, deferred to 4.0 (#53) label Oct 12, 2026
@lehni
lehni force-pushed the fix/rc-bm-find-hooks branch 2 times, most recently from 20afa1c to 6fa6364 Compare October 12, 2026 21:02
@lehni
lehni force-pushed the fix/rc-bm-find-hooks branch from 6fa6364 to 2bc9e41 Compare October 12, 2026 21:19
@lehni
lehni merged commit 7b14a78 into next Oct 12, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.0 Breaking change, deferred to 4.0 (#53)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant