#110068Extbase does not remove single FAL FileReference when setting property to null
Description
When using a single FAL relation in an Extbase domain model, setting the property to null and persisting the object does not remove the underlying sys_file_reference record. The relation is no longer available through Extbase after persistence, but the sys_file_reference record remains fully intact in the backend and database, including its complete file reference configuration.
$news->setImage(null);
$this->newsRepository->update($news);
$this->persistenceManager->persistAll();
Expected result
- The corresponding sys_file_reference record is removed.
- The relation is fully deleted.
Actual result
- The parent field (e.g. image) is updated and Extbase no longer returns the relation.
- The corresponding sys_file_reference record remains in the database.
- The file reference remains fully preserved in the backend and can still be found there unchanged.
- The relation is therefore only partially removed.
Comparison with ObjectStorage relations
For a multi-value FAL relation using ObjectStorage, Extbase behaves differently and removes relations correctly out of the box:
$news->removeImage($image);
$this->newsRepository->update($news);
$this->persistenceManager->persistAll();
In this case, the corresponding relation is removed as expected and no manual cleanup is required.
Workaround
The relation can be removed explicitly via:
$this->fileReferenceRepository->remove($news->getImage());
However, this should not be necessary when setting a nullable single-valued FAL relation to null.
Question
Is this intended behavior, or should Extbase remove the corresponding sys_file_reference record automatically when a single FAL relation is set to null and persisted? The current behavior appears incomplete or inconsistent, since multi-value FAL relations managed via ObjectStorage are cleaned up automatically, while equivalent single-value FAL relations are not.