Issue Bug Closed

#110193DataHandler::undeleteRecordRelations() cascade fails for foreign_field inline relations

Kay Wienöbst 07/13/26, 16:03 updated 08/11/26, 08:51

Description

Steps to reproduce

  1. Configure an inline TCA relation with foreign_field (standard IRRE pattern), where both parent and child table have delete => 'deleted' soft-delete.
  2. Add some children to a parent record.
  3. Delete the parent via DataHandler — the IRRE cascade correctly soft-deletes the children.
  4. Undelete the parent via DataHandler (cmd[$table][$uid][undelete] = 1).

Expected

The children are soft-deleted-cascaded back to deleted=0 alongside the parent, mirroring the delete-cascade path in DataHandler::deleteRecord_procFields().

Actual

Only the parent is restored. Children remain deleted=1. No error, no log entry.

Root cause

DataHandler::undeleteRecordRelations() (Classes/DataHandling/DataHandler.php, around line 6093–6098):

$relationHandler->start($value, $foreignTable, '', $uid, $table, $fieldConfig);
$relationHandler->undeleteRecord = true;
foreach ($relationHandler->itemArray as $reference) {
    $this->undeleteRecord($reference['table'], (int)$reference['id']);
}   

The undeleteRecord flag is set after start() has already been called. Internally start() dispatches to RelationHandler::readForeignField(), which evaluates the flag on line 840:

$useDeleteClause = !$this->undeleteRecord;

At that point undeleteRecord is still false, so $useDeleteClause is true and a DeletedRestriction is added to the QueryBuilder. The SELECT ends up as … WHERE foreign_field = $uid AND deleted = 0, filtering out precisely the soft-deleted children we want to restore. $itemArray is empty, the following foreach is a no-op.

Setting undeleteRecord = true afterwards has no effect since the query is already gone.

The todo comment on line 6075 (“Add functional test undelete coverage to verify details, some details seem to be missing.”@) suggests this path has been under-tested.

Proposed fix

Move the undeleteRecord = true assignment before start():

$relationHandler = $this->createRelationHandlerInstance();
$relationHandler->undeleteRecord = true;
$relationHandler->start($value, $foreignTable, '', $uid, $table, $fieldConfig);
foreach ($relationHandler->itemArray as $reference) {
    $this->undeleteRecord($reference['table'], (int)$reference['id']);
}   

undeleteRecord() itself is idempotent — line 5948 early-returns for records with deleted === false — so accidentally loading a live child (if any) is harmless.

Same fix should be applied to the FlexForm branch around line 6108 if the equivalent path is added there (currently a @todo).

Environment

  • TYPO3 14.3.4
  • PHP 8.4
  • Reproducer setup: parent table without versioningWS, child table without versioningWS, standard inline foreign_field relation, user in Live workspace.

Reviews 2

History 24

  1. Kay Wienöbst commented and changed status Under Review Resolved done 0 % 100 % <span data-processor="relativetime" data-value="2026-07-24T15:40:12+00:00" > 07/24/26, 15:40 </span>

    Applied in changeset commit:b7e7c0ba92719517743e636e705613ed829ccb48.