Skip to content

Commit

Permalink
Assume nullable=true as the default for @joincolumn
Browse files Browse the repository at this point in the history
Necessary to make some example configurations pass tests where `nullable` is not configured but must be assumed to be true (the default according to the docs) to be able to break cycles.
  • Loading branch information
mpdude committed Mar 11, 2023
1 parent fc6f2ab commit ae4c1f2
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/Doctrine/ORM/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -1303,10 +1303,15 @@ private function computeAssociationTopoSort(array $objects): array
$joinColumns = reset($assoc['joinColumns']);

// 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. We should, however, assume that this default is applied at another level and 'nullable'
// is defined here. In case it is not, assume `false` which is a more conservative default from the dependency computation
// point of view.
$isNullable = ! empty($joinColumns['nullable']);
// 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.
//
// From the dependency computation point of view, `false` would be a safer default, but that won't work with all examples and
// reproduce cases given.
//
// Same in \Doctrine\ORM\Tools\EntityGenerator::isAssociationIsNullable or \Doctrine\ORM\Persisters\Entity\BasicEntityPersister::getJoinSQLForJoinColumns,
// to give two examples.
$isNullable = !isset($joinColumns['nullable']) || $joinColumns['nullable'];

if (isset($objects[$targetOid])) {
$calc->addDependency($targetOid, $oid, $isNullable);
Expand Down

0 comments on commit ae4c1f2

Please sign in to comment.