Skip to content

Cascading deletion doesn't work with cascadeCallbacks if you first trash related elements. #68

@kolorafa

Description

@kolorafa

If you have cascadeCallbacks enabled.

The 'purge'=>true only works if the related (hasMany) elements are not trashed.

Steps to reproduce:

  1. Have 2 tables, both with Trash.
  2. First table hasMany secondTable with Dependent true and setCascadeCallbacks true
  3. delete() entity from firstTable
  4. delete(['purge' => true]) the same entity

Expected result:

Have both entity from firstTable and related entities from secondTable hard deleted (purged)

Actual result:

Related entities from secondTable are left as soft deleted (or you get constraint violation if set).

It's because the DependentDeleteHelper.php doesn't see those related elements because by default the Trash Behavior hides deleted items.

foreach ($association->find()->where($conditions)->all()->toList() as $related) {

https://github.com/cakephp/cakephp/blob/323997781a608191192066b883201a12c3c5b2f2/src/ORM/Association/DependentDeleteHelper.php#L56

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