I have been having an issue with the $this->delete() method that deletes a record from the corresponding model. Previously I had the statement contained in an if statement that would detect a return false; coming back from the delete() and then fail.
The problem is that it fails 100% of the time. I have gone through and double checked the relationships quite a few times to make sure I’m taking care of, and deleting all dependencies prior to deleting this record.
Currently I have removed the statement from the “if” block and just made it execute no matter what and it works without error.
If I was getting a false returned before, shouldn’t I be seeing some sort of error?
Ex:
if ($this->customeDelete($id)) {
if ($this->ModelName->ModelName2->ModelName3->customDelete($id)) {
if ($this->ModelName4->deleteAll(array('foreign_id' => $id))) {
// Prior to this line, all deletes were successful. This is where it fails.
//The previous lines are custom model methods
if ($this->delete($id)) { // If statement that is failing
$this->commit();
return true;
}
}
}
}
It looks like you call
$this->cutomDeleteon the record you want to delete, and then$this->deleteon the same record. If customDelete has already deleted the data, then delete won’t have anything to delete and therefore will return false.