Hi Everyone, following the documentation
https://docs.phalcon.io/pt/latest/reference/models.html#deleting-records
I've create a model with a beforeDelete method that contain a rule not to delete a certain record, lets say for example when the 'year' value of the record is 3000.
public function beforeDelete()
{
if ($this->year == 3000) {
echo "Cannot delete Robot of year 3000";
return false;
}
return true;
}
Then I've created a controller action where I get this record and call delete on it
public function deleteAction()
{
$robot = Robots::findById(10);
if ($robot != false) {
if ($robot->delete() == false) {
echo "Sorry, we can’t delete the robot right now: \n";
foreach ($robot->getMessages() as $message) {
echo $message, "<br />";
}
} else {
echo "The robot was deleted successfully!";
}
}
}
This is what I get if I run that action
Cannot delete Robot of year 3000The robot was deleted successfully!
The record is not deleted from DB, but $robot->delete() is return TRUE, is that the correct behaviour? Shouldn't return FALSE?
Thank you