Doctrine query: delete with limit
One solution that works is to use native SQL with Doctrine like this (instead of DQL).
$limit = 10;$sql = 'DELETE FROM my_entity WHERE cost = 50 LIMIT ' . $numberOfDeletion;$stmt = $entityManager->getConnection()->prepare($sql);$stmt->execute();
setMaxResults
works only in some cases. Doctrine seems to ignore it if it's not managed.
check the Doctrine doc : https://www.doctrine-project.org/projects/doctrine1/en/latest/manual/dql-doctrine-query-language.html#driver-portability
If it does not work, try in native SQL, like the other solution posted.