diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index c0b0dd8c302..56615807f4e 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1154,7 +1154,11 @@ private function getCommitOrder(array $entityChangeSet = null) $joinColumns = reset($assoc['joinColumns']); - $calc->addDependency($targetClass->name, $class->name, (int)empty($joinColumns['nullable'])); + $calc->addDependency( + $targetClass->name, + $class->name, + (int) (($joinColumns['nullable'] ?? true) === false) + ); // If the target class has mapped subclasses, these share the same dependency. if ( ! $targetClass->subClasses) { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php new file mode 100644 index 00000000000..0d86fffb037 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php @@ -0,0 +1,96 @@ +_schemaTool->createSchema([ + $this->_em->getClassMetadata(DDC6499A::class), + $this->_em->getClassMetadata(DDC6499B::class), + ]); + } + + /** + * {@inheritDoc} + */ + protected function tearDown() : void + { + parent::tearDown(); + + $this->_schemaTool->dropSchema([ + $this->_em->getClassMetadata(DDC6499A::class), + $this->_em->getClassMetadata(DDC6499B::class), + ]); + } + + public function testIssue() : void + { + $b = new DDC6499B(); + $a = new DDC6499A(); + + $this->_em->persist($a); + + $a->b = $b; + + $this->_em->persist($b); + + $this->_em->flush(); + + self::assertInternalType('integer', $a->id); + self::assertInternalType('integer', $b->id); + } + + public function testIssueReversed() : void + { + $b = new DDC6499B(); + $a = new DDC6499A(); + + $a->b = $b; + + $this->_em->persist($b); + $this->_em->persist($a); + + $this->_em->flush(); + + self::assertInternalType('integer', $a->id); + self::assertInternalType('integer', $b->id); + } +} + +/** @Entity */ +class DDC6499A +{ + /** @Id @Column(type="integer") @GeneratedValue */ + public $id; + + /** @JoinColumn(nullable=false) @OneToOne(targetEntity=DDC6499B::class) */ + public $b; +} + +/** @Entity */ +class DDC6499B +{ + /** @Id @Column(type="integer") @GeneratedValue */ + public $id; + + /** @ManyToOne(targetEntity="DDC6499A") */ + private $a; +}