-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cascading deletion doesn't work with cascadeCallbacks if you first trash related elements. #68
Comments
The only solution I see for this problem is to loop through all dependent associations and disable the trash behavior (or set some flag so that You are welcome to submit a patch for that (or any other solution). |
Thanks for checking it. I did also check multiple places. I could also loop over associations and use But I think manually handling deletion of trashed items in Current dirty work-around I have found is to have (separate second) associations that is only used for delete with |
Yeah that would be inline with the approach I suggested above.
You could extend HasMany/HasOne::cacacadeDelete() and override Table::hasMany/hasOne() to use your custom association classes, but that's an app level solution. |
@ADmad
Both cases are not possible, because if delete fail for any reason, you can't undone those changes, and those changes affect all next ORM queries on that table. So If your app have some handling for failed deletions (even printing some page with error message) - then you are f... as you could accidentally also fetch trashed entities. You can't use |
If you have
cascadeCallbacks
enabled.The
'purge'=>true
only works if the related (hasMany) elements are not trashed.Steps to reproduce:
Dependent true
andsetCascadeCallbacks true
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 theTrash Behavior
hides deleted items.https://github.com/cakephp/cakephp/blob/323997781a608191192066b883201a12c3c5b2f2/src/ORM/Association/DependentDeleteHelper.php#L56
The text was updated successfully, but these errors were encountered: