Conversation
abdusco
force-pushed
the
fix/factory-composable-relations
branch
3 times, most recently
from
September 6, 2026 17:56
dfab765 to
02149f4
Compare
abdusco
force-pushed
the
fix/factory-composable-relations
branch
from
September 6, 2026 18:18
02149f4 to
55db4d7
Compare
abdusco
marked this pull request as ready for review
September 6, 2026 18:52
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.
Problem
Creating an optional direct parent relationship through a factory currently writes the child once, creates the parent, then writes the child again to set its foreign key. The final data is correct, but the second write is unnecessary and triggers observable update side effects.
This is not the best behavior for temporal or versioned tables, audit triggers, and any other database feature that reacts to updates.
Minimal reproduction
Generate factories for these two tables:
Create an update-audit trigger on
videos, then create a video with a new sponsor:Expected: the returned video includes its sponsor and no
videosupdate occurs.Actual on
main: the video includes its sponsor, but the audit trigger records oneUPDATEafter both records have been created.I reproduced this on local PostgreSQL 18.4: upstream
mainrecorded one update; this branch recorded zero.Fix
Create direct parent and child relationships as part of one creation flow whenever the relationship is represented by the child foreign key. The factory inserts the child with the parent foreign key already set, avoiding the follow-up relationship update. Explicit foreign-key values remain sufficient to reference an existing parent, and cascading parent setup only fills relationships that are required.