DDC-3929: Iterating results documentation #4806

Open
opened 2026-01-22 14:49:44 +01:00 by admin · 0 comments
Owner

Originally created by @doctrinebot on GitHub (Oct 1, 2015).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user ruscon:

http://doctrine-orm.readthedocs.org/projects/doctrine-orm/en/latest/reference/batch-processing.html#id1

<?php
$batchSize = 20;
$i = 0; // <- BUG. if $i = 0, then you have commit after first iteration :)
$q = $em->createQuery('select u from MyProject\Model\User u');
$iterableResult = $q->iterate();
while (($row = $iterableResult->next()) !== false) {
    $em->remove($row[0]);
    if (($i % $batchSize) === 0) {
        $em->flush(); // Executes all deletions.
        $em->clear(); // Detaches all objects from Doctrine!
    }
    <ins></ins>$i;
}
$em->flush();
Originally created by @doctrinebot on GitHub (Oct 1, 2015). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user ruscon: http://doctrine-orm.readthedocs.org/projects/doctrine-orm/en/latest/reference/batch-processing.html#id1 ``` java <?php $batchSize = 20; $i = 0; // <- BUG. if $i = 0, then you have commit after first iteration :) $q = $em->createQuery('select u from MyProject\Model\User u'); $iterableResult = $q->iterate(); while (($row = $iterableResult->next()) !== false) { $em->remove($row[0]); if (($i % $batchSize) === 0) { $em->flush(); // Executes all deletions. $em->clear(); // Detaches all objects from Doctrine! } <ins></ins>$i; } $em->flush(); ```
admin added the Bug label 2026-01-22 14:49:44 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4806