Replies: 1 comment
-
Hi @marcoas, if I understand you correctly, you want to catch a situation where a foreign key constraint makes deletion impossible. I believe, the postDelete() hook you mentioned is not suitable for this. Instead, one way would be to define a preDelete() hook that checks if a constraint exists that prevents deletion. If so, you would execute your custom code notifying you and doing whatever else is needed and then let the preDelete() hook return false to stop the deletion. On the other hand, if everything is fine constraint wise, just let the hook return true so deletion can continue. This is how I understand https://propelorm.org/documentation/06-behaviors.html#pre-and-post-hooks-for-save-and-delete-methods. On the other hand you could also work on your model in such a way that those nasty dependencies don’t even exist which prevent you from deleting something. Or, as a third option, you could cascade the deletion if your model and business logic allows for. Hope these ideas help you somehow. Best, |
Beta Was this translation helpful? Give feedback.
-
(Translated by Google)
Hello
I have already created and loaded for all the tables, a behavior very similar to the example in: timestampable.
There, I override the preInsert and preUpdate methods.
That works very well.
Now I need to be able to control this situation:
When doing a DELETE and it fails due to a foreign key constraint, I want to catch the error, and perform a particular action. In my case, perform a "logical delete" (set the "disabled" field of the record to true)
Can this be done with a behavior?
I tried to do it with the postDelete hook, but due to the constraint error, this method does not get executed.
I tried putting a delete function in the behavior, with the intention of overriding that method, but it doesn't seem to work or I didn't do it right.
Can someone tell me how to do this?
Beta Was this translation helpful? Give feedback.
All reactions