Problems when I try to delete
Hi,
I have too many modules related to others. For example, the module portal users and the module company.
In the database, the table company has a foreign key to the users table.
If a try to delete a user, the portal throws database error and I understand why. I can't delete a user if other tables are related to him.
But my question is how can I do to display a friendly message error when this happen instead of
A Database Error Occurred
Error Number: 1451
Cannot delete or update a parent row: a foreign key constraint fails...
I realized that the delete function in the module.php file use flags to handle the errors
// Flags
$any_success = $any_failure = FALSE;
foreach ($posted as $id)
{
if ($this->model->delete(array($this->model->key_field() => $id)))
{
$any_success = TRUE;
}
else
{
$any_failure = TRUE;
}
}
According to this, the database error shouldn't be displayed. Just a message should be displayed according to the flag.
How can I do to avoid the database error?
Comments
Before I discover this, I realized of the on_before_delete hook. I try to use it to delete some files when I'm going to delete a model with files, but It seems that the hook is not recognized. I even try to print some data but nothing was displayed.
I'm using the hook in the model of the module, is that ok?