CakePHP : Delete multiple records

With CakePHP, you can remove multiple records from a database table using the deleteAll() model method.

deleteAll() Usage

$this -> Model -> deleteAll($conditions, $cascade = true);

Lets say that you wanted to remove all the records for a specific user from the Item model. Below is a quick example.

deleteAll() Example

$this -> Item -> deleteAll(array('Item.user_id' => 13));

…where 13 would be the ID of the specific user.

Off course…you can completely truncate a table with the same method, this time removing all conditions. Below is an example of how to truncate a database table using CakePHP.

deleteAll() table truncate

$this -> Model -> deleteAll();

Comments

  1. By Peter Minne

  2. By jets

  3. By parmjeet

  4. By Synue

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>