How to handle a SQL error response in Editor
How to handle a SQL error response in Editor
Hello,
This is really not a problem but a how to question:
If I have a table that has a field that is a foreign key in another table, SQL responses properly with an error message stating that the row cannot be deleted when the user tries to delete the row in the Editor.
My question is how to best to handle the error in the Editor and tell the user that this row cannot be deleted. Right now it just shows the SQL error string in red at the bottom of the Editor popup.
This is the response that I would like to handle better:
SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails ...
Thanks
This question has an accepted answers - jump to answer
Answers
There are a couple of options:
ON DELETE CASCADE
so the child row will be deletedpostSubmit
to detect the error message returned from the server and modify it to be something more using friendly.From your description I suspect that 3. will be the one you want. It isn't ideal I realise! 1.6 is going to introduce cancellable server-side events, so you can effectively do validation prior to a delete, which will be a much neater way of doing this.
Allan
Thanks Allan for the suggestion. I look forward to 1.6 also.
That was really helpful! Here is an example for custom error handling using "postSubmit". Maybe of use for someone who finds this post.