1
0
mirror of synced 2025-02-20 06:03:15 +03:00

DDC-633 - Fix Eager ManyToOne or OneToOne relations being replaced by a proxy instead.

This commit is contained in:
Benjamin Eberlei 2010-08-08 11:05:30 +02:00
parent 11b25422d6
commit 251247c16f
2 changed files with 76 additions and 1 deletions

View File

@ -1912,7 +1912,13 @@ class UnitOfWork implements PropertyChangedListener
// If it might be a subtype, it can not be lazy
$newValue = $assoc->load($entity, null, $this->em, $associatedId);
} 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()
$newValueOid = spl_object_hash($newValue);
$this->entityIdentifiers[$newValueOid] = $associatedId;

View 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;
}