Merge conflict Gerrit cannot merge this change. It needs a rebase onto main.
96722[BUGFIX] Delete the former child of a 1:1 relation in Extbase
Commit message
Test this change
Run a command in your clone of the TYPO3 Core. Then try what the change does and vote on Verified in Gerrit. How to review a patch
- Check out patch set 4
-
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/22/96722/4 && git checkout FETCH_HEAD - Cherry-pick onto main
-
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/22/96722/4 && git cherry-pick FETCH_HEAD
Review
-
Code review CR +1 Needs a vote
- Simon Schaufelberger +1
- Benni Mack +1
-
Verified V +1 Needs a vote
- Oliver Klee +1
- Simon Schaufelberger +1
- Benni Mack +1
- core-ci +1 CI
Issues 3
Files 24
- typo3/sysext/core/Documentation/Changelog/15.0/Important-78961-ExtbaseDeletesFormerChildOfToOneRelation.rstnew+44 −0
- typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php+75 −1
- typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example/Classes/Domain/Model/Person.php+14 −0
- typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example/Classes/Domain/Model/Post.php+1 −1
- typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example/Configuration/TCA/tx_blogexample_domain_model_person.php+7 −0
- typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/ToOneRelationMove/AvatarMovedJaneFirst.csvnew+7 −0
- typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/ToOneRelationMove/AvatarMovedJohnFirst.csvnew+7 −0
- typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/ToOneRelationMove/ImportAvatar.csvnew+13 −0
- typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/ToOneRelationMove/ImportInfo.csvnew+10 −0
- typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/ToOneRelationMove/ImportPhoto.csvnew+13 −0
- typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/ToOneRelationMove/InfoMovedPost1First.csvnew+7 −0
- typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/ToOneRelationMove/InfoMovedPost2First.csvnew+7 −0
- typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/ToOneRelationMove/PhotoMovedJaneFirst.csvnew+7 −0
- typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/ToOneRelationMove/PhotoMovedJohnFirst.csvnew+7 −0
- typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/ToOneRelationRemoval/AvatarCleared.csvnew+7 −0
- typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/ToOneRelationRemoval/ImportAvatar.csvnew+13 −0
- typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/ToOneRelationRemoval/ImportInfo.csvnew+10 −0
- typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/ToOneRelationRemoval/ImportPhoto.csvnew+13 −0
- typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/ToOneRelationRemoval/InfoCleared.csvnew+7 −0
- typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/ToOneRelationRemoval/InfoReplaced.csvnew+8 −0
Show 4 more files
- typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/ToOneRelationRemoval/PhotoCleared.csvnew+7 −0
- typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/ToOneRelationRemoval/PhotoReplaced.csvnew+8 −0
- typo3/sysext/extbase/Tests/Functional/Persistence/ToOneRelationMoveTest.phpnew+441 −0
- typo3/sysext/extbase/Tests/Functional/Persistence/ToOneRelationRemovalTest.phpnew+425 −0
Review log 1014
-
Benni Mack uploaded patch set 1 10/15/26, 13:58
-
core-ci voted on patch set 1 V +1 10/15/26, 14:50 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/111201
-
Alexander Schnitzler commented on patch set 1 CR -1 10/15/26, 18:05
Looking at how doctrine/orm handles this is quite revealing. Without orphanRemoval, it behaves like Extbase did before this patch: it only detects changes on the owning side, and FileReference is technically the owning side here, as it holds the uid of the person. Nulling the reference on the inverse side (Person) neither removes nor detaches it; the foreign key simply stays. With orphanRemoval (the counterpart of #[Cascade('remove')]), Doctrine does remove the former reference, also when it is nulled or replaced on the inverse side. So the cascade part of this patch matches Doctrine; the detach-without-cascade part does not. Second, moving a reference to another record. As FileReference is an entity of its own (title, alternative, crop), handing it over must keep it: $john->setPhoto($jane->getPhoto()); $jane->setPhoto(null); In Doctrine this is a single change on the owning side, $photo->setPerson($john), resulting in one UPDATE of the reference, independent of the flush order. With orphanRemoval the moved reference would be deleted instead, as Doctrine assumes orphan-removed children are privately owned. That matches this patch with #[Cascade('remove')]. Without cascade, however, Extbase now loses the reference: * Before this patch, the reference stayed attached to Jane (uid_foreign = 1), John's photo column got the uid of the reference. * With this patch, the reference is detached from Jane and attached to nobody (uid_foreign = 0, tablenames and fieldname empty), no matter whether Jane or John is persisted first. The cause is that Extbase never attaches an existing object to a new parent in a 1:1 relation stored via foreign_field, only new objects get the foreign field set in insertObject(). For 1:n relations, attachObjectToParentObject() does this. Before this patch that gap was hidden, now the detach makes it lose the reference. I'd suggest attaching an existing object to the new parent as well. Once that exists, the persist order starts to matter: if John is persisted first, Jane's detach would undo John's attach. So the detach should only happen while the reference still points to the former parent. I've written functional tests for both persist orders that fail on PS1. Happy to push them as a separate patch if you like. -
Alexander Schnitzler uploaded patch set 2
CR -1V +110/16/26, 09:05 -
Alexander Schnitzler commented on patch set 2 10/16/26, 09:07
Reply
I think looking at doctine here is the wrong benchmark but it is interesting to understand how another ORM handles this. PS2 does bench against how the core handles things via DH. Red tests are expected as the fix has been removed and more tests have been added first. -
core-ci voted on patch set 2 V -1 10/16/26, 09:18 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/111329
-
Alexander Schnitzler uploaded patch set 3
V -110/16/26, 10:00 -
core-ci voted on patch set 3 V +1 10/16/26, 10:17 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/111346
-
Oliver Klee voted on patch set 3 V +1 10/17/26, 17:11
-
Alexander Schnitzler uploaded patch set 4
V +110/29/26, 12:26 -
core-ci voted on patch set 4 V +1 10/29/26, 12:34 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/112798
-
Oliver Klee voted on patch set 4 V +1 10/29/26, 13:35
-
Benni Mack commented on patch set 4 CR +1 V +1 10/30/26, 21:47
Reply
Done -
Simon Schaufelberger voted on patch set 4 CR +1 V +1 11/06/26, 00:52