Skip to content

Write the foreign keys of has-many and has-one relates in upsertGraph() with noUpdate (#53) - #345

Merged
lehni merged 1 commit into
nextfrom
fix/rc-noupdate-relate
Oct 12, 2026
Merged

lehni merged 1 commit into
nextfrom
fix/rc-noupdate-relate

Conversation

@lehni

@lehni lehni commented Oct 12, 2026 •

Copy link
Copy Markdown

What

With relate and noUpdate, upsertGraph() patches the foreign keys of the models it relates through a HasManyRelation or HasOneRelation. GraphPatchAction adds the relation's related properties of nodes planned as relate to the properties it writes, next to the BelongsToOneRelation and BelongsToManyRelation keys it already collects with noUpdate. The other properties of these models stay unwritten.

Why

noUpdate only skips the property updates, while relate explicitly asks for the relate. The foreign key that GraphRelate or the parent's insert sets on the related model was never in the properties to write, so no query ran and upsertGraph() reported success with the model still related to its old owner. BelongsToOneRelation and ManyToManyRelation relates already write with noUpdate. This has been the case since 1.5.0, where upsertGraph() was rewritten. The same fix for 3.9.1 is in #355.

Tests

should only write the foreign key when hasManyRelation and hasOneRelation models are related with noUpdate: true relates a model into a HasOneRelation and moves one from another owner into a HasManyRelation, and checks that only the foreign keys change. It fails 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-noupdate-relate branch from c85c06a to 8b3c94d Compare October 12, 2026 21:02
@lehni
lehni force-pushed the fix/rc-noupdate-relate branch from 8b3c94d to 37affb5 Compare October 12, 2026 21:18
@lehni
lehni merged commit 5cdf15d 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