1
0
Fork 0
mirror of synced 2025-04-01 12:26:11 +03:00

Merge branch 'fix/#6499-#6533-fix-commit-order-calculation-consider-all-join-column-fields'

Close #6499
Close #6533
This commit is contained in:
Marco Pivetta 2017-08-11 22:17:02 +02:00
commit 2a58645cb5
No known key found for this signature in database
GPG key ID: 4167D3337FD9D629
2 changed files with 101 additions and 1 deletions

View file

@ -1154,7 +1154,11 @@ class UnitOfWork implements PropertyChangedListener
$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) {

View file

@ -0,0 +1,96 @@
<?php
namespace Doctrine\Tests\Functional\Ticket;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Tests\OrmFunctionalTestCase;
/**
* @group #6499
*
*
* Specifically, DDC6499B has a dependency on DDC6499A, and DDC6499A
* has a dependency on DDC6499B. Since DDC6499A#b is not nullable,
* the DDC6499B should be inserted first.
*/
class DDC6499Test extends OrmFunctionalTestCase
{
/**
* {@inheritDoc}
*/
protected function setUp() : void
{
parent::setUp();
$this->_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;
}