CakePHP’s Model class offers a few ways to delete records from your database.
delete(int $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:
<?php
$this->Comment->delete($this->request->data('Comment.id'));
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.
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.
Example:
<?php
// 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.
Note
deleteAll() will return true even if no records are deleted, as the conditions for the delete query were successful and no matching records remain.