Merge conflict Gerrit cannot merge this change. It needs a rebase onto main.

Review main Ready for review

96722[BUGFIX] Delete the former child of a 1:1 relation in Extbase

Benni Mack CR +1 V +1 Expert +1158 −2 updated 11/10/26, 09:22

Commit message

Setting a 1:1 relation stored via foreign_field to null, or replacing
the related object, only updated the parent record. The former child
kept pointing to the parent and was loaded again on the next request.
Moving a child to another parent left it attached to the former one,
and the parent column received the uid of the child instead of the
number of children.

Extbase now behaves like the backend: the former child is deleted
once all objects are persisted, unless it was handed over to another
parent in the same commit. A moved child keeps its row and points to
the new parent, and the parent column holds the number of children.

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

Show 4 more files

Review log 1014

  1. Benni Mack uploaded patch set 1 10/15/26, 13:58

  2. 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

  3. 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.
  4. Alexander Schnitzler uploaded patch set 2 CR -1 V +1 10/16/26, 09:05

  5. 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.
  6. 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

  7. Alexander Schnitzler uploaded patch set 3 V -1 10/16/26, 10:00

  8. 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

  9. Oliver Klee voted on patch set 3 V +1 10/17/26, 17:11

  10. Alexander Schnitzler uploaded patch set 4 V +1 10/29/26, 12:26

  11. 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

  12. Oliver Klee voted on patch set 4 V +1 10/29/26, 13:35

  13. Benni Mack commented on patch set 4 CR +1 V +1 10/30/26, 21:47

    Reply

    Done
  14. Simon Schaufelberger voted on patch set 4 CR +1 V +1 11/06/26, 00:52