Commit order reversed? #7210

Closed
opened 2026-01-22 15:47:02 +01:00 by admin · 3 comments
Owner

Originally created by @olivier1980 on GitHub (Aug 9, 2023).

Since release v2.16 this line of code won't save the entities in order of the loop anymore:

 foreach ($importDossier->getKlanten() as $klant) {
          $klant->setIsActive(true);
          $this->entityManager->persist($klant);
}

The last line to be executed will get an earlier id in the DB than the first iteration of the loop...which seems weird. Is this expected behaviour?

I noticed work was done on the commit order here: https://github.com/doctrine/orm/pull/10547

Originally created by @olivier1980 on GitHub (Aug 9, 2023). Since release v2.16 this line of code won't save the entities in order of the loop anymore: ``` foreach ($importDossier->getKlanten() as $klant) { $klant->setIsActive(true); $this->entityManager->persist($klant); } ``` The last line to be executed will get an earlier id in the DB than the first iteration of the loop...which seems weird. Is this expected behaviour? I noticed work was done on the commit order here: https://github.com/doctrine/orm/pull/10547
admin closed this issue 2026-01-22 15:47:03 +01:00
Author
Owner

@olivier1980 commented on GitHub (Aug 9, 2023):

Apparently this is now the new behaviour:

    Do not make any assumptions in your code about the number of queries
    it takes to flush changes, about the ordering of ``INSERT``, ``UPDATE``
    and ``DELETE`` queries or the order in which entities will be processed.

and they don't consider it a BC breaking change lol

@olivier1980 commented on GitHub (Aug 9, 2023): Apparently this is now the new behaviour: ``` Do not make any assumptions in your code about the number of queries it takes to flush changes, about the ordering of ``INSERT``, ``UPDATE`` and ``DELETE`` queries or the order in which entities will be processed. ``` and they don't consider it a BC breaking change lol
Author
Owner

@greg0ire commented on GitHub (Aug 9, 2023):

Damn right we don't! And the paragraph you're quoting does not document new behavior. It merely newly documents that using the ORM does not and never did guarantee any particular insertion order.

@greg0ire commented on GitHub (Aug 9, 2023): Damn right we don't! And the paragraph you're quoting does not document new behavior. It merely newly documents that using the ORM does not and never did guarantee any particular insertion order.
Author
Owner

@derrabus commented on GitHub (Aug 10, 2023):

FTR, duplicate of #10864

@derrabus commented on GitHub (Aug 10, 2023): FTR, duplicate of #10864
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7210