DDC-633 - Fix Eager ManyToOne or OneToOne relations being replaced by a proxy instead.
This commit is contained in:
parent
11b25422d6
commit
251247c16f
@ -1912,7 +1912,13 @@ class UnitOfWork implements PropertyChangedListener
|
|||||||
// If it might be a subtype, it can not be lazy
|
// If it might be a subtype, it can not be lazy
|
||||||
$newValue = $assoc->load($entity, null, $this->em, $associatedId);
|
$newValue = $assoc->load($entity, null, $this->em, $associatedId);
|
||||||
} else {
|
} else {
|
||||||
$newValue = $this->em->getProxyFactory()->getProxy($assoc->targetEntityName, $associatedId);
|
if ($assoc->fetchMode == Mapping\AssociationMapping::FETCH_EAGER) {
|
||||||
|
// TODO: Maybe it could be optimized to do an eager fetch with a JOIN inside
|
||||||
|
// the persister instead of this rather unperformant approach.
|
||||||
|
$newValue = $this->em->find($assoc->targetEntityName, $associatedId);
|
||||||
|
} else {
|
||||||
|
$newValue = $this->em->getProxyFactory()->getProxy($assoc->targetEntityName, $associatedId);
|
||||||
|
}
|
||||||
// PERF: Inlined & optimized code from UnitOfWork#registerManaged()
|
// PERF: Inlined & optimized code from UnitOfWork#registerManaged()
|
||||||
$newValueOid = spl_object_hash($newValue);
|
$newValueOid = spl_object_hash($newValue);
|
||||||
$this->entityIdentifiers[$newValueOid] = $associatedId;
|
$this->entityIdentifiers[$newValueOid] = $associatedId;
|
||||||
|
69
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC633Test.php
Normal file
69
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC633Test.php
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../../../TestInit.php';
|
||||||
|
|
||||||
|
class DDC633Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||||
|
{
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
try {
|
||||||
|
$this->_schemaTool->createSchema(array(
|
||||||
|
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC633Patient'),
|
||||||
|
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC633Appointment'),
|
||||||
|
));
|
||||||
|
} catch(\Exception $e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testOneToOneEager()
|
||||||
|
{
|
||||||
|
$app = new DDC633Appointment();
|
||||||
|
$pat = new DDC633Patient();
|
||||||
|
$app->patient = $pat;
|
||||||
|
$pat->appointment = $app;
|
||||||
|
|
||||||
|
$this->_em->persist($app);
|
||||||
|
$this->_em->persist($pat);
|
||||||
|
$this->_em->flush();
|
||||||
|
$this->_em->clear();
|
||||||
|
|
||||||
|
$eagerAppointment = $this->_em->find(__NAMESPACE__ . '\DDC633Appointment', $app->id);
|
||||||
|
|
||||||
|
$this->assertNotType('Doctrine\ORM\Proxy\Proxy', $eagerAppointment->patient);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Entity
|
||||||
|
*/
|
||||||
|
class DDC633Appointment
|
||||||
|
{
|
||||||
|
/** @Id @Column(type="integer") @GeneratedValue */
|
||||||
|
public $id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @OneToOne(targetEntity="DDC633Patient", inversedBy="appointment", fetch="EAGER")
|
||||||
|
*/
|
||||||
|
public $patient;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Entity
|
||||||
|
*/
|
||||||
|
class DDC633Patient
|
||||||
|
{
|
||||||
|
/** @Id @Column(type="integer") @GeneratedValue */
|
||||||
|
public $id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @OneToOne(targetEntity="DDC633Appointment", mappedBy="patient")
|
||||||
|
*/
|
||||||
|
public $appointment;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user