With CakePHP, you can remove multiple records from a database table using the deleteAll() model method.
deleteAll() Usage
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
…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.








September 7th, 2008 at 10:14 am
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.
January 21st, 2010 at 3:02 am
hey, nice tipics buddy… i used this & working great.
July 21st, 2010 at 3:01 am
I am new in cakephp .Thanks for the tips..
March 3rd, 2011 at 4:53 pm
Thanks working grate
July 5th, 2011 at 10:43 pm
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.
October 5th, 2011 at 10:39 am
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;”);