A call to the delete method is returning me the following error.
Error Number:
ERROR: update or delete on table "matricula" violates foreign key constraint "matricula_matricula_cobranca_fk" on table "movement_cobranca" DETAIL: Key (matricula) = (1908) is still referenced from table "
DELETE FROM REGISTRATION WHERE REGISTRATION IN (1908)
Filename: models / Matricula_model.php
Line Number: 166
But I need to handle this error and display a message to the user only stating that it did not work.
In the controller I am just validating the input and calling in the Model.
Controller
public function excluir($matricula) {
if ($this->matricula_model->excluir($matricula)->dbReturn === true)
echo json_encode(['codigo' => 0]);
else
echo json_encode(['codigo' => 1]);
}
Model
function excluir($matricula)
{
if ( $lista_matricula != "" ) {
$sql_exclusao = "DELETE FROM matricula WHERE matricula IN (". $matricula .")";
if (!$ret = $this->db->query($sql_exclusao))
{
return $this->buildReturnObject($this->db->error(),false);
}
return $this->buildReturnObject('',$ret);
}
return false;
}
I know why the error is occurring and I do not need to treat it at the moment (because it is referring to bd). What I need is a way to return a value for my view (I used booleans, but could be any other) to be able to display an alert, a message or whatever. I need my return to be true or false to pass to my view a code (0 or 1) and display a message according to it, however the way I did it is not working.