Issue Bug Closed

#72613Extbase does not delete 1:1 related objects with @cascade remove

Simon Schaufelberger 01/09/16, 14:46 updated 05/03/16, 10:28

Description

given following model (simplified) with @cascade annotation:

class Model {

    /**
     * Address
     *
     * @var Address
     * @lazy
     * @cascade remove
     */
    protected $address;

    /**
     * Deletes the address
     */
    public function unsetAddress() {
        $this->address = null;
    }
}

when I call in my controller:

$this->model->unsetAddress();
$this->modelRepository->update($this->model);

I would expect that the related Address will also get deleted but instead just the address property of Model will bet set NULL in database.

As a manual workaround I currently have to add the following code:

if ($model->getAddress()) {
    $this->addressRepository->remove($model->getAddress());
}

It seeams like the @cascade remove annotation is only considered for ObjectStorage:

https://docs.typo3.org/typo3cms/ExtbaseFluidBook/5-Domain/2-implementing-the-domain-model.html#implementing-relationships-between-domain-objects

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.