Repository navigation
Fix replacing one-sided relationships after target removal - #847
Merged
Merged
Conversation
Member
Author
|
This change is part of the following stack: Change managed by git-spice. |
hrach
force-pushed
the
js/fix-one-sided-replacement
branch
from
November 8, 2026 19:27
d4bb855 to
c2e63ea
Compare
Avoid resolving the previous target when replacing an unloaded one-sided relationship. This allows assigning a replacement or null after the previous target was removed, without throwing NoResultException. Preserve tracking of already loaded targets and updates to reverse relationships. Add database regression tests using the existing Book::nextPart relationship as one-sided through test-local metadata. Clear the stored reference and delete its target through DBAL, leaving the loaded owner's lazy reference stale while preserving foreign-key constraints. Verify entity, ID, new-entity and null assignments through persistence and reload, including an already loaded reference. Fixes #846
Append the current HasOne entity to the tracked entities instead of combining the arrays with a union. Both arrays can contain key 0, causing a tracked previous target to hide the replacement and skip its pending changes. Cover bidirectional 1:1 and m:1 relationships using the existing fixtures. Verify that both previous and replacement targets are queued and their changes survive persistence and reload.
hrach
force-pushed
the
js/fix-one-sided-replacement
branch
from
November 8, 2026 20:09
c2e63ea to
036ada4
Compare
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.
Replacing a lazy one-sided relationship after its target was removed tried to
load the deleted entity and threw NoResultException. Only load and track the
previous target when a reverse relationship needs updating, allowing replacement
or null assignment without resolving the deleted target.
Add 16 regression cases for one-sided 1:1 and m:1 relationships with loaded and
lazy references, entity and ID assignments, new targets, and null. Verify the
relationship after reloading and ensure the deleted target stays deleted.
Validation: all 328 tests passed using PostgreSQL; PHPStan and DressCode checks
for the changed files passed.
Fixes #846