This is my simple code:
$this->deleteAll(array('expiration <=' => CakeTime::format('Y-m-d H:i:s', time())));
I see this in the query result:
SELECT `Token`.`id` FROM `cake`.`tokens` AS `Token` WHERE `expiration` <= '2012-10-23 14:37:04'
DELETE `Token` FROM `cake`.`tokens` AS `Token` WHERE `Token`.`id` = (6)
In short, it seems that CakePHP first retrieve the id of records corresponding to the conditions, then proceed to delete using the id retrieved.
But this makes no sense, since it may proceed directly using the condition given:
DELETE `Token` FROM `cake`.`tokens` AS `Token` WHERE `expiration` <= '2012-10-23 14:37:04'
Why does this happen?
Fetching and deleting records individually is required if you either want to run the model callbacks or cascading delete to remove depending records. So pass false for
$cascadeand$callbacksparameter for thedeleteAll()function and the records will be deleted using single query without any retrieving of records first.