[PR #10689] Compute entity-level commit order for entity insertions #12547

Closed
opened 2026-01-22 16:14:23 +01:00 by admin · 0 comments
Owner

Original Pull Request: https://github.com/doctrine/orm/pull/10689

State: closed
Merged: Yes


Make the UoW find a commit order for entity insertions not on the class, but at the entity level. This is the third step to break https://github.com/doctrine/orm/pull/10547 into smaller PRs suitable for reviewing. It uses the new topological sort implementation from #10592 and the refactoring from #10651.

Current situation

UnitOfWork::getCommitOrder() would compute the entity sequence on the class level with the following code:

70477d81e9/lib/Doctrine/ORM/UnitOfWork.php (L1310-L1325)

Suggested change

  • Instead of considering the classes of all entities that need to be inserted, updated or deleted, consider the new (inserted) entities only. We only need to find a sequence in situations where there are foreign key relationships between two new entities.
  • In the dependency graph, add edges for all to-one association target entities.
  • Make edges "optional" when the association is nullable.

Extra bonus

This is what the DALL·E AI thinks it looks like when the UnitOfWork is scheduling the sequence of entity insertions.

DALL·E 2023-05-08 18 32 54

**Original Pull Request:** https://github.com/doctrine/orm/pull/10689 **State:** closed **Merged:** Yes --- Make the UoW find a commit order for entity insertions not on the class, but at the entity level. This is the third step to break https://github.com/doctrine/orm/pull/10547 into smaller PRs suitable for reviewing. It uses the new topological sort implementation from #10592 and the refactoring from #10651. #### Current situation `UnitOfWork::getCommitOrder()` would compute the entity sequence on the class level with the following code: https://github.com/doctrine/orm/blob/70477d81e96c0044ad6fd8c13c37b2270d082792/lib/Doctrine/ORM/UnitOfWork.php#L1310-L1325 #### Suggested change * Instead of considering the classes of all entities that need to be inserted, updated or deleted, consider the new (inserted) entities only. We only need to find a sequence in situations where there are foreign key relationships between two _new_ entities. * In the dependency graph, add edges for all to-one association target entities. * Make edges "optional" when the association is nullable. #### Extra bonus This is what the DALL·E AI thinks it looks like when the `UnitOfWork` is scheduling the sequence of entity insertions. ![DALL·E 2023-05-08 18 32 54](https://user-images.githubusercontent.com/1202333/236879540-40e98ff2-581e-41d0-a09e-aa8c622bbc18.png)
admin added the pull-request label 2026-01-22 16:14:23 +01:00
admin closed this issue 2026-01-22 16:14:24 +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#12547