#78961Extbase removing one file reference not working
Description
After setting a property pointing to a file reference to NULL and persisting, the file_reference still exists in the database and is back when refreshing the page.
(Even with the cascade remove@ annotation, the reference isn’t deleted.)
// Relevant SQL
CREATE TABLE tx_experiments_domain_model_book (
-- ...
cover_image int(11) DEFAULT '0' NOT NULL,
-- ...
)
// Relevant TCA
// ...
'cover_image' => [
'label' => 'Cover Image',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('cover_image', [
'maxitems' => 1,
'minitems' => 0,
'appearance' => [
'createNewRelationLinkTitle' => 'LLL:EXT:fluid_styled_content/Resources/Private/Language/Database.xlf:tt_content.asset_references.addFileReference'
],
'foreign_match_fields' => [
'fieldname' => 'cover_image',
'tablenames' => 'tx_experiments_domain_model_book',
'table_local' => 'sys_file',
],
'foreign_types' => $GLOBALS['TCA']['tt_content']['columns']['image']['config']['foreign_types']
], $GLOBALS['TYPO3_CONF_VARS']['SYS']['mediafile_ext'])
],
// ...
// Model
class Book extends AbstractEntity
{
// ...
/**
* @var \TYPO3\CMS\Extbase\Domain\Model\FileReference
* @cascade remove
*/
protected $coverImage;
// ...
}
// Controller
class BookController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
{
// ...
protected function updateAction(Book $book)
{
$model->setCoverImage(null);
$this->bookRepository->update($book);
// ...
}
// ...
}
After taking a look at TYPO3\CMS\Extbase\Persistence\Generic\Backend it was clear to me why it does not work:
In the persistObject method there’s no clause to check for properties that have been changed from a DomainObject to null and have a @cascade remove annotation.
I have created a patch that would add the missing behaviour. (See Backend.patch)
Reviews 2
Related issues 2
Files 1
History 613
-
Gerrit Code Review pushed patch set 1 for master to change 52067 status
NewUnder Review <span data-processor="relativetime" data-value="2017-03-16T16:35:10+00:00" > 03/16/17, 16:35 </span> -
Gerrit Code Review pushed patch set 2 for master to change 52067 <span data-processor="relativetime" data-value="2018-02-06T11:12:34+00:00" > 02/06/18, 11:12 </span>
-
Gerrit Code Review pushed patch set 3 for master to change 52067 <span data-processor="relativetime" data-value="2018-03-01T22:04:12+00:00" > 03/01/18, 22:04 </span>
-
Susanne Moog commented and changed status
Under ReviewAccepted <span data-processor="relativetime" data-value="2019-03-01T19:23:08+00:00" > 03/01/19, 19:23 </span> -
Benni Mack changed Sprint Focus Stabilization Sprint <span data-processor="relativetime" data-value="2023-06-06T13:02:02+00:00" > 06/06/23, 13:02 </span>
-
Georg Ringer changed Related to #110068 <span data-processor="relativetime" data-value="2026-09-02T13:17:42+00:00" > 09/02/26, 13:17 </span>
-
Georg Ringer changed Related to #81897 <span data-processor="relativetime" data-value="2026-09-02T13:47:16+00:00" > 09/02/26, 13:47 </span>
-
Jan Kornblum commented <span data-processor="relativetime" data-value="2026-09-03T10:55:22+00:00" > 09/03/26, 10:55 </span>
Still an issue, at least in v12, https://forge.typo3.org/issues/110068
-
Gerrit Code Review pushed patch set 1 for main to change 96722 status
AcceptedUnder Review <span data-processor="relativetime" data-value="2026-10-15T13:58:26+00:00" > 10/15/26, 13:58 </span> -
Alexander Schnitzler commented and changed assigned to Alexander Schnitzler <span data-processor="relativetime" data-value="2026-10-16T07:24:42+00:00" > 10/16/26, 07:24 </span>
I think the
#[Cascade('remove')]in this report is misleading. According to the documentation, cascade remove controls what happens to related objects when the parent object is deleted. Here the parent (the book) is not deleted, only its cover image is set to null, so cascade remove should not matter.The case itself is still relevant, though. The bug is that setting a 1:1 relation stored via
foreign_fieldto null has no effect, with or without cascade:$book->setCoverImage(null); $bookRepository->update($book); $persistenceManager->persistAll();The parent column is updated, but the
sys_file_referencestill points to the book viauid_foreign/@tablenames@/@fieldname@. As the relation is resolved viaforeign_field, the reference is back on the next load (for a non-lazy property). It is also still shown in the backend.This is not specific to FAL: a plain inline child (
type=inline,foreign_field,maxitems1) behaves the same way.For comparison, FormEngine handles this by sending a delete command for the removed child, so in the backend a removed 1:1 child is always deleted.
-
Gerrit Code Review pushed patch set 2 for main to change 96722 <span data-processor="relativetime" data-value="2026-10-16T09:05:51+00:00" > 10/16/26, 09:05 </span>
-
Gerrit Code Review pushed patch set 3 for main to change 96722 <span data-processor="relativetime" data-value="2026-10-16T10:00:54+00:00" > 10/16/26, 10:00 </span>
-
Gerrit Code Review pushed patch set 4 for main to change 96722 <span data-processor="relativetime" data-value="2026-10-29T12:26:46+00:00" > 10/29/26, 12:26 </span>
Patch has been abandoned.