Skip to content

Commit

Permalink
Fix commit order computation for self-referencing entities with appli…
Browse files Browse the repository at this point in the history
…cation-provided IDs

This excludes such associations from the commit order computation, since the foreign key constraint will be satisfied when inserting the row.

See #10735 for more details about this edge case.
  • Loading branch information
mpdude committed Aug 1, 2023
1 parent f26946b commit f01d107
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/Doctrine/ORM/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,14 @@ private function computeInsertExecutionOrder(): array
continue;
}

// An entity that references back to itself _and_ uses an application-provided ID
// (the "NONE" generator strategy) can be exempted from commit order computation.
// See https://github.com/doctrine/orm/pull/10735/ for more details on this edge case.
// A non-NULLable self-reference would be a cycle in the graph.
if ($targetEntity === $entity && $class->isIdentifierNatural()) {
continue;
}

// According to https://www.doctrine-project.org/projects/doctrine-orm/en/2.14/reference/annotations-reference.html#annref_joincolumn,
// the default for "nullable" is true. Unfortunately, it seems this default is not applied at the metadata driver, factory or other
// level, but in fact we may have an undefined 'nullable' key here, so we must assume that default here as well.
Expand Down

0 comments on commit f01d107

Please sign in to comment.