Skip to content

Apply first() of relation mapping modifiers and onBuild() hooks per parent (#127) - #338

Merged
lehni merged 1 commit into
nextfrom
fix/rc-first-per-parent
Oct 12, 2026
Merged

lehni merged 1 commit into
nextfrom
fix/rc-first-per-parent

Conversation

@lehni

@lehni lehni commented Oct 12, 2026 •

Copy link
Copy Markdown

What

first() in a relation mapping's modify, or in an onBuild() hook of a graph modifier, limits the related models of each parent to one again under the limitPerParent default. LimitPerParentOperation reads first() as a limit of 1 when the query is built, and first() doesn't unwrap the result of a query that is limited per parent.

Why

WhereInEagerOperation turned first() into limit(1) right after the graph modifiers ran. The relation mapping's modify and onBuild() hooks run later, while the query is built, so their first() stayed a plain first(): only one parent of the whole batch got a related model and the others got null. 3.9.0 with limitPerParent: true applied it per parent.

Tests

  • should apply first() of a relation mapping modify per parent
  • should apply first() of an onBuild() hook per parent

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-first-per-parent branch 2 times, most recently from b7df3f3 to 4174299 Compare October 12, 2026 19:35
@lehni
lehni force-pushed the fix/rc-first-per-parent branch from 4174299 to 67e9328 Compare October 12, 2026 21:14
@lehni
lehni merged commit bbae4c1 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