DDC-748 - Fix bug in EntityManager::refresh() when entity has an owning side many-to-one bi-directional association
This commit is contained in:
parent
24c6bb3f46
commit
13da816f4e
@ -653,7 +653,7 @@ class BasicEntityPersister
|
|||||||
if ($found = $this->_em->getUnitOfWork()->tryGetById($joinColumnValues, $targetClass->rootEntityName)) {
|
if ($found = $this->_em->getUnitOfWork()->tryGetById($joinColumnValues, $targetClass->rootEntityName)) {
|
||||||
$this->_class->reflFields[$field]->setValue($entity, $found);
|
$this->_class->reflFields[$field]->setValue($entity, $found);
|
||||||
// Complete inverse side, if necessary.
|
// Complete inverse side, if necessary.
|
||||||
if ($assoc['inversedBy']) {
|
if ($assoc['inversedBy'] && $assoc['type'] & ClassMetadata::ONE_TO_ONE) {
|
||||||
$inverseAssoc = $targetClass->associationMappings[$assoc['inversedBy']];
|
$inverseAssoc = $targetClass->associationMappings[$assoc['inversedBy']];
|
||||||
$targetClass->reflFields[$inverseAssoc['fieldName']]->setValue($found, $entity);
|
$targetClass->reflFields[$inverseAssoc['fieldName']]->setValue($found, $entity);
|
||||||
}
|
}
|
||||||
|
64
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC748Test.php
Normal file
64
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC748Test.php
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||||
|
|
||||||
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
use Doctrine\Tests\Models\CMS\CmsUser;
|
||||||
|
use Doctrine\Tests\Models\CMS\CmsArticle;
|
||||||
|
use Doctrine\Tests\Models\CMS\CmsAddress;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../../../TestInit.php';
|
||||||
|
|
||||||
|
class DDC748Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||||
|
{
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
$this->useModelSet('cms');
|
||||||
|
parent::setUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRefreshWithManyToOne()
|
||||||
|
{
|
||||||
|
$user = new CmsUser();
|
||||||
|
$user->name = "beberlei";
|
||||||
|
$user->status = "active";
|
||||||
|
$user->username = "beberlei";
|
||||||
|
|
||||||
|
$article = new CmsArticle();
|
||||||
|
$article->setAuthor($user);
|
||||||
|
$article->text = "foo";
|
||||||
|
$article->topic = "bar";
|
||||||
|
|
||||||
|
$this->_em->persist($user);
|
||||||
|
$this->_em->persist($article);
|
||||||
|
$this->_em->flush();
|
||||||
|
|
||||||
|
$this->assertType('Doctrine\Common\Collections\Collection', $user->articles);
|
||||||
|
$this->_em->refresh($article);
|
||||||
|
$this->assertTrue($article !== $user->articles, "The article should not be replaced on the inverse side of the relation.");
|
||||||
|
$this->assertType('Doctrine\Common\Collections\Collection', $user->articles);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRefreshOneToOne()
|
||||||
|
{
|
||||||
|
$user = new CmsUser();
|
||||||
|
$user->name = "beberlei";
|
||||||
|
$user->status = "active";
|
||||||
|
$user->username = "beberlei";
|
||||||
|
|
||||||
|
$address = new CmsAddress();
|
||||||
|
$address->city = "Bonn";
|
||||||
|
$address->country = "Germany";
|
||||||
|
$address->street = "A street";
|
||||||
|
$address->zip = 12345;
|
||||||
|
$address->setUser($user);
|
||||||
|
|
||||||
|
$this->_em->persist($user);
|
||||||
|
$this->_em->persist($address);
|
||||||
|
$this->_em->flush();
|
||||||
|
|
||||||
|
$this->_em->refresh($address);
|
||||||
|
$this->assertSame($user, $address->user);
|
||||||
|
$this->assertSame($user->address, $address);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user