Issue Bug Closed

#79014DataHandler not deleting inline and MM references if base table does not have a "delete"-field leads to DatabaseRecordException⁠⁠⁠⁠

Stephan Großberndt 12/16/16, 12:00 updated 12/02/25, 14:36

Description

DataHandler calls deleteRecord_procFields() to check and delete inline and MM references only if the base table has a “delete”-field:

        if ($deleteField && !$forceHardDelete) {
            ...

            // before (un-)deleting this record, check for child records or references
            $this->deleteRecord_procFields($table, $uid, $undeleteRecord);
            $this->databaseConnection->exec_UPDATEquery($table, 'uid=' . (int)$uid, $updateFields);
            // Delete all l10n records as well, impossible during undelete because it might bring too many records back to life
            if (!$undeleteRecord) {
                $this->deleteL10nOverlayRecords($table, $uid);
            }
        } else {
            ...

            // Delete the hard way...:
            $this->databaseConnection->exec_DELETEquery($table, 'uid=' . (int)$uid);
            $this->deleteL10nOverlayRecords($table, $uid);
        }

This is wrong. If a table does not contain a defined “delete”-field in TCA and has inline or MM-relations and a record from this table is deleted, the related and mm records stay in the database.

If you try to open the record on the other side of the mm-relation you get a ⁠⁠⁠⁠@DatabaseRecordException⁠⁠⁠⁠@ with ⁠⁠⁠⁠@#1437656081: Record with uid XXX from table tx_extension_mytable@ not found⁠⁠⁠⁠ because the relation in the mm table is still there but the record is not.

Reviews 6

History 939

Show 414 earlier messages
  1. Stephan Großberndt changed status New In Progress assigned to Stephan Großberndt <span data-processor="relativetime" data-value="2016-12-16T12:14:18+00:00" > 12/16/16, 12:14 </span>

  2. Gerrit Code Review pushed patch set 1 for master to change 50987 status In Progress Under Review <span data-processor="relativetime" data-value="2016-12-16T12:25:09+00:00" > 12/16/16, 12:25 </span>

  3. Stephan Großberndt commented <span data-processor="relativetime" data-value="2018-03-02T11:21:07+00:00" > 03/02/18, 11:21 </span>

    Configuration/TCA/tx_blogexample_domain_model_blog.php

    <?php
    return [
        'ctrl' => [
            'title' => 'blog',
            'label' => 'title'
        ],
        'interface' => [
            'showRecordFieldList' => 'title, posts'
        ],
        'columns' => [
            'title' => [
                'label' => 'title',
                'config' => [
                    'type' => 'input'
                ]
            ],
            'posts' => [
                'label' => 'posts',
                'config' => [
                    'type' => 'inline',
                    'foreign_table' => 'tx_blogexample_domain_model_post',
                    'foreign_field' => 'blog'
                ]
            ],
        ],
        'types' => [
            '1' => ['showitem' => 'title, posts']
        ]
    ];

    Configuration/TCA/tx_blogexample_domain_model_post.php

    <?php
    return [
        'ctrl' => [
            'title' => 'post',
            'label' => 'title'
        ],
        'interface' => [
            'showRecordFieldList' => 'title, blog'
        ],
        'columns' => [
            'title' => [
                'label' => 'title',
                'config' => [
                    'type' => 'input'
                ]
            ],
            'blog' => [
                'label' => 'blog',
                'config' => [
                    'type' => 'select',
                    'renderType' => 'selectSingle',
                    'foreign_table' => 'tx_blogexample_domain_model_blog',
                    'maxitems' => 1
                ]
            ],
        ],
        'types' => [
            '1' => ['showitem' => 'title, blog']
        ]
    ];

    ext_tables.sql

    CREATE TABLE tx_blogexample_domain_model_blog (
        uid int(11) unsigned DEFAULT '0' NOT NULL auto_increment,
        pid int(11) DEFAULT '0' NOT NULL,
        deleted tinyint(4) unsigned DEFAULT '0' NOT NULL,
        title varchar(255) DEFAULT '' NOT NULL,
        posts varchar(255) DEFAULT '' NOT NULL,
        PRIMARY KEY (uid),
        KEY parent (pid)
    );
    
    CREATE TABLE tx_blogexample_domain_model_post (
        uid int(11) unsigned DEFAULT '0' NOT NULL auto_increment,
        pid int(11) DEFAULT '0' NOT NULL,
        deleted tinyint(4) unsigned DEFAULT '0' NOT NULL,
        blog int(11) DEFAULT '0' NOT NULL,
        title varchar(255) DEFAULT '' NOT NULL,
        PRIMARY KEY (uid),
        KEY parent (pid)
    );

    If 'delete' => 'deleted', is defined in Configuration/TCA/tx_blogexample_domain_model_post.php:$TCA['ctrl'] and you delete the blog the related posts will get deleted=1, if its not defined, nothing happens to them. (I typed this up from memory without re-testing..)

  1. Stephan Großberndt commented and changed status Under Review Resolved done 0 % 100 % <span data-processor="relativetime" data-value="2025-05-28T16:55:09+00:00" > 05/28/25, 16:55 </span>

    Applied in changeset commit:3b10a3ca18630b34771054da85c40807f306621e.