Stop a deletion in "beforeDelete" event ?

HI First I would like to know if there is a way to do some "beforeDelete" events? I didn't find any of this sort on docs https://docs.phalconphp.com/en/3.2/db-models-events

next, I would like to know if it's possible to stop the transaction to do an update instead of delete ?

I made an Interface SoftDeletableModelInterface and a trait SoftDeletableTrait Actually, in my Trait, I have a property $deleted (and getter/setter) and I would like to add the beforeDelete event to stop the deletion and set $deleted property to true.

Thanks

edited 19d ago

If there is beforeDelete() method in Model Class you can return FALSE and then deletion will be stopped.

In the case when you want to do update instead of delete, try do $this->update() and then return FALSE.



838

Thanks a lot. I found a beforeDelete method few minutes after posting my questions, but didn't see any example of what I would like to try so i'll try that myself.



838

Oh I didn't see that, thanks. But I like the way to have only one declaration for my softDelete Behaviour. If I do like in the docs, I need to do it for all the models soft deletable. in my case I just need to implements the interface and use the Trait.

I'll see what's the better solution for me, Thanks for showing me that part of the docs.



66.8k
class Base extends phalcon\Mvc\Model {
    //config for soft delete goes here
}

class Product extends Base {
    //you have soft delete here aswell ;-)
}