[2.0] DDC-194 - Fixed infinite recursion issue with references and @PostLoad annotation by telling proxy to be loaded before calling EntityPersister->load...
This commit is contained in:
parent
59c6449076
commit
845c85552e
@ -261,10 +261,10 @@ namespace <namespace> {
|
|||||||
}
|
}
|
||||||
private function _load() {
|
private function _load() {
|
||||||
if ( ! $this->_loaded) {
|
if ( ! $this->_loaded) {
|
||||||
|
$this->_loaded = true;
|
||||||
$this->_entityPersister->load($this->_identifier, $this);
|
$this->_entityPersister->load($this->_identifier, $this);
|
||||||
unset($this->_entityPersister);
|
unset($this->_entityPersister);
|
||||||
unset($this->_identifier);
|
unset($this->_identifier);
|
||||||
$this->_loaded = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public function __isInitialized__() { return $this->_loaded; }
|
public function __isInitialized__() { return $this->_loaded; }
|
||||||
|
@ -59,6 +59,26 @@ class LifecycleCallbackTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
$this->assertEquals('Alice', $user2->getName());
|
$this->assertEquals('Alice', $user2->getName());
|
||||||
$this->assertEquals('Hello World', $user2->getValue());
|
$this->assertEquals('Hello World', $user2->getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group DDC-194
|
||||||
|
*/
|
||||||
|
public function testGetReferenceWithPostLoadEventIsDelayedUntilProxyTrigger()
|
||||||
|
{
|
||||||
|
$entity = new LifecycleCallbackTestEntity;
|
||||||
|
$entity->value = 'hello';
|
||||||
|
$this->_em->persist($entity);
|
||||||
|
$this->_em->flush();
|
||||||
|
$id = $entity->getId();
|
||||||
|
|
||||||
|
$this->_em->clear();
|
||||||
|
|
||||||
|
$reference = $this->_em->getReference('Doctrine\Tests\ORM\Functional\LifecycleCallbackTestEntity', $id);
|
||||||
|
$this->assertFalse($reference->postLoadCallbackInvoked);
|
||||||
|
|
||||||
|
$reference->getId(); // trigger proxy load
|
||||||
|
$this->assertTrue($reference->postLoadCallbackInvoked);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @Entity @HasLifecycleCallbacks */
|
/** @Entity @HasLifecycleCallbacks */
|
||||||
@ -99,6 +119,10 @@ class LifecycleCallbackTestEntity
|
|||||||
* @Column(type="string")
|
* @Column(type="string")
|
||||||
*/
|
*/
|
||||||
public $value;
|
public $value;
|
||||||
|
|
||||||
|
public function getId() {
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
/** @PrePersist */
|
/** @PrePersist */
|
||||||
public function doStuffOnPrePersist() {
|
public function doStuffOnPrePersist() {
|
||||||
|
@ -11,11 +11,10 @@ require_once __DIR__ . '/../../TestInit.php';
|
|||||||
/**
|
/**
|
||||||
* Tests the generation of a proxy object for lazy loading.
|
* Tests the generation of a proxy object for lazy loading.
|
||||||
* @author Giorgio Sironi <piccoloprincipeazzurro@gmail.com>
|
* @author Giorgio Sironi <piccoloprincipeazzurro@gmail.com>
|
||||||
|
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||||
*/
|
*/
|
||||||
class ReferenceProxyTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
class ReferenceProxyTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||||
{
|
{
|
||||||
private $product;
|
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
$this->useModelSet('ecommerce');
|
$this->useModelSet('ecommerce');
|
||||||
|
Loading…
Reference in New Issue
Block a user