If you have cascadeCallbacks enabled.
The 'purge'=>true only works if the related (hasMany) elements are not trashed.
Steps to reproduce:
- Have 2 tables, both with Trash.
- First table hasMany secondTable with
Dependent true and setCascadeCallbacks true
- delete() entity from firstTable
- 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