Conversation
…to new changes, preserving backward compatibility. Add related info to readme.
| $bindingKey = (array)$association->getBindingKey(); | ||
| $conditions = array_combine($foreignKey, $entity->extract($bindingKey)); | ||
|
|
||
| foreach ($association->find('onlyTrashed')->where($conditions) as $related) { |
There was a problem hiding this comment.
If a record is being hard deleted then all it's dependent records should be hard deleted, not just the ones which are trashed, otherwise you could end up with orphaned records. So the withTrashed finder should be used here not onlyTrashed.
| */ | ||
| public function cascadingEmptyTrash(?EntityInterface $entity = null) | ||
| { | ||
| $result = $this->emptyTrash($entity); |
There was a problem hiding this comment.
The dependent records should be deleted before parents, otherwise you will get delete failures if foreign key constraint is set on the dependent table.
| * @param \Cake\Datasource\EntityInterface|null $entity to delete. | ||
| * @return bool|\Cake\Datasource\EntityInterface|int | ||
| */ | ||
| public function emptyTrash(?EntityInterface $entity = null) |
There was a problem hiding this comment.
Don't mix deletion of single and multiple records, it makes the API ugly. Static analyzers won't be able to detect the proper return type.
|
Besides deleting of associated records the use of So a better way to solve all problems would be to just use |
Just ran into this same issue today. Need to delete files only when a record has been hard-deleted. An option to use callbacks would be great or an event like |
|
If I understand correctly the topic, I set It would be nice to be able to set cascadeCallbacks to true by default for all relations (to avoid accidentally forgetting) so any and all related deletions trigger delete events. |
…and modify emptyTrash method to adapt to new changes, preserving backward compatibility. Add related info to readme.