CakePHP’s Model class offers a few ways to delete records from your database.
delete(integer $id = null, boolean $cascade = true);
Deletes the record identified by $id. By default, also deletes records dependent on the record specified to be deleted.
For example, when deleting a User record that is tied to many Recipe records (User ‘hasMany’ or ‘hasAndBelongsToMany’ Recipes):
If your database supports foreign keys and cascading deletes, it’s often more efficient to rely on that feature than CakePHP’s cascading. The one benefit to using the cascade feature of Model::delete() is that it allows you to leverage behaviors and model callbacks:
You can hook custom logic into the delete process using the beforeDelete and afterDelete callbacks present in both Models and Behaviors. See Callback Methods for more information.
If you delete a record with dependent records and one of their delete callbacks, e.g. beforeDelete returns false, it will not stop the further event propagation nor does it change the return value of the initial delete.
deleteAll(mixed $conditions, $cascade = true, $callbacks = false)
deleteAll() is similar to delete(), except that deleteAll() will delete all records that match the supplied conditions. The $conditions array should be supplied as a SQL fragment or array.
Return boolean True on success, false on failure.
// Delete with array conditions similar to find() $this->Comment->deleteAll(array('Comment.spam' => true), false);
If you delete with either callbacks and/or cascade, rows will be found and then deleted. This will often result in more queries being issued. Associations will be reset before the matched records are deleted in deleteAll(). If you use bindModel() or unbindModel() to change the associations, you should set reset to false.
deleteAll() will return true even if no records are deleted, as the conditions for the delete query were successful and no matching records remain.