Skip to content

Commit

Permalink
Merge branch 'fix/#6499-#6533-fix-commit-order-calculation-consider-a…
Browse files Browse the repository at this point in the history
…ll-join-column-fields'

Close #6499
Close #6533
  • Loading branch information
Ocramius committed Aug 11, 2017
2 parents 6d428c9 + 1ede3c5 commit 2a58645
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/Doctrine/ORM/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
96 changes: 96 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 2a58645

Please sign in to comment.