PGBI/cakephp3-soft-delete

Behavior

Opened this issue · 3 comments

Hey man,

Am I allowed to convert this awesome trait to a behavior for the Cake 3 Utils Plugin? It would be easier to implement, and could be documented at http://cakemanager.org/docs/utils/1.0/.

Greetz

Bob

PGBI commented

At first I had tried to write a behavior instead of a trait, but did not manage to do what I wanted.

With a behavior, you cannot override Model::delete(). So the way to do is to catch the beforeDelete event in the behavior, update the soft delete field, and then stop the propagation of the event to avoid the hard deletion to happen. But by doing so, you prevent the cascade deletion to other models as well as counter cache updates, which I think was not satisfactory.

But if you find a way to make all this work with a behavior, feel free to convert it!

I will try to find a way but thank's for your information.

For now I see no solution to override the delete()-method. What do you think about implementing this trait into the Utils-plugin to make it easier to use (because you got a big library)...