Bug #72613

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

Added by Simon Schaufelberger over 3 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Must have
Assignee:
-
Category:
Extbase
Target version:
-
Start date:
2016-01-09
Due date:
% Done:

0%

TYPO3 Version:
4.7
PHP Version:
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

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

History

#1 Updated by Stefan Froemken over 3 years ago

  • Status changed from New to Needs Feedback

Hello Simon,

you only update the model. To see "cascade remove" in action you have to remove your model and while it is removed, all related objects (in your case the address model) will also be removed in one step. Without "cascade remove" only your model will be removed, but the address models are still there.
As long as you only update your model "cascade remove" will do nothing, and your model will be updated with an empty address.

Stefan

#2 Updated by Alexander Opitz over 3 years ago

  • Status changed from Needs Feedback to Closed

No feedback within the last 90 days => closing this issue.

If you think that this is the wrong decision or experience this issue again, then please write to the mailing list typo3.teams.bugs with issue number and an explanation or open a new ticket and add a relation to this ticket number.

Also available in: Atom PDF