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();


  1. Peter Minne on September 7, 2008

    The “deleteAll” requires a condition as first parameter. So your example to truncate a table should be something like this:

    $this->Model->deleteAll(‘1 = 1’, false);

    Personally I think it would make sense if the cake team would implement an additional “truncate” method.

  2. jets on January 21, 2010

    hey, nice tipics buddy… i used this & working great.

  3. parmjeet on July 21, 2010

    I am new in cakephp .Thanks for the tips..

  4. vancouver web development on March 3, 2011

    Thanks working grate 🙂

  5. Pawan Rote on July 5, 2011

    Hey, The above condition works, thanks for the tip.
    One more thing I want point out that same condition can be treated as SQL injection.

  6. Synue on October 5, 2011

    Let’s not forget that $this->Model->deleteAll(’1 = 1′, false); will only delete the records from the table. You would still have the auto increment option set.

    To sucessfully truncate a table you can $this->ModelName->query(“TRUNCATE TABLE table_name;”);


Leave a Reply

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

Pin It on Pinterest

Subscribe To Our Newsletter

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!

%d bloggers like this: