Skip to content

The child-references of a record are not marked as deleted if enableCascadingDelete is TRUE #25

Closed

Description

@Moongazer

Lets say we have the following record relation: a book (parent) has multiple chapters (children), defined like this:

TCA configuration:

//book.php
      'ctrl' => [
        'delete' => 'deleted',
      ],
      'columns' => [
        'chapters' => [
            'config' => [
                'type' => 'inline',
                'foreign_table' => 'chapter',
                'foreign_field' => 'book_uid',
                'maxitems' => 9999,
                'behaviour' => [
                    'enableCascadingDelete' => TRUE,
                ],
            ],
        ],
      ],

//chapter.php
      'ctrl' => [
        'delete' => 'deleted',
      ],

Model: Book.php

/**
 * @T3api\ApiResource(
 *     itemOperations={
 *          "delete"={
 *              "method"="DELETE",
 *              "path"="/book/{id}",
 *          },
 *     },
 * )
 */
class Book extends AbstractEntity {
    /**
     * @var ObjectStorage<Chapter>
     * @T3api\Serializer\Groups({
     *     "api_book_post_collection",
     * })
     * @T3api\ORM\Cascade("persist")
     */
    protected $chapters;
}

The request DELETE /api/book/123 will set deleted=1 for parent record 123, but not for the child-records.
Instead, if the record 123 is deleted in the TYPO3 backend list view, also the child-records are marked as deleted.

I tried it also with the replaced annotation @T3api\ORM\Cascade("delete") but with the same result.

Activity

  1. klamparski commented on Feb 19, 2021

    @klamparski
    Collaborator

    Extbase uses some things from TCA configuration but does not reflect all the features. As far as I know (can't test it at the moment) this one is not reflected and that's why it works for you only in backend. To achieve cascade remove on Extbase you need to use its annotation:

    **
     * @TYPO3\CMS\Extbase\Annotation\ORM\Cascade("remove")
     */
    public $property;
    

    Regarding cascade persistence annotation from t3api - it's just security enhancement of Extbase as Extbase does not support any other cascade than remove, unfortunately. We hope some day we can remove it and relay on pure Extbase also for persistence. Here you can find more info and example usage of cascade persistence.

    Please try it with Extbase's cascade remove annotation and let us know if it worked. Thanks in advance.

  2. Moongazer commented on Feb 20, 2021

    @Moongazer
    ContributorAuthor

    Yes indeed, that works. Thank you very much for the explanation and sorry for opening the ticket than. Just was a bit confused 👍

  3. locked and limited conversation to collaborators on Feb 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions