Skip to content

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

Merged
lehni merged 1 commit into
mainfrom
fix/rc-noupdate-relate-main
Oct 13, 2026
Merged

lehni merged 1 commit into
mainfrom
fix/rc-noupdate-relate-main

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 that it relates to the properties it writes, next to the BelongsToOneRelation 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 the graph sets on the related model was never among the properties to write, so no query ran and upsertGraph() reported success with the model still related to its old owner, or to none. BelongsToOneRelation and ManyToManyRelation relates already write with noUpdate. This has been the case since 1.5.0, where upsertGraph() was rewritten.

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.

The same fix for 4.0 is in #345. #334 and #336 also add a ## 3.9.1 section to the changelog; whichever merges later combines them.

lehni added a commit that referenced this pull request Oct 12, 2026
@lehni
lehni force-pushed the fix/rc-noupdate-relate-main branch from d1995d7 to 492ba2b Compare October 12, 2026 21:01
@lehni lehni changed the title Write the foreign keys of has-many and has-one relates in upsertGraph() with noUpdate Write the foreign keys of has-many and has-one relates in upsertGraph() with noUpdate (#355) Oct 12, 2026
@lehni
lehni force-pushed the fix/rc-noupdate-relate-main branch from 492ba2b to b5d3867 Compare October 13, 2026 07:40
@lehni
lehni merged commit 638abca into main Oct 13, 2026
8 checks passed
@lehni lehni mentioned this pull request Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant