Commit 845c8555 authored by beberlei's avatar beberlei

[2.0] DDC-194 - Fixed infinite recursion issue with references and @PostLoad...

[2.0] DDC-194 - Fixed infinite recursion issue with references and @PostLoad annotation by telling proxy to be loaded before calling EntityPersister->load...
parent 59c64490
......@@ -261,10 +261,10 @@ namespace <namespace> {
}
private function _load() {
if ( ! $this->_loaded) {
$this->_loaded = true;
$this->_entityPersister->load($this->_identifier, $this);
unset($this->_entityPersister);
unset($this->_identifier);
$this->_loaded = true;
}
}
public function __isInitialized__() { return $this->_loaded; }
......
......@@ -59,6 +59,26 @@ class LifecycleCallbackTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertEquals('Alice', $user2->getName());
$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 */
......@@ -99,6 +119,10 @@ class LifecycleCallbackTestEntity
* @Column(type="string")
*/
public $value;
public function getId() {
return $this->id;
}
/** @PrePersist */
public function doStuffOnPrePersist() {
......
......@@ -11,11 +11,10 @@ require_once __DIR__ . '/../../TestInit.php';
/**
* Tests the generation of a proxy object for lazy loading.
* @author Giorgio Sironi <piccoloprincipeazzurro@gmail.com>
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/
class ReferenceProxyTest extends \Doctrine\Tests\OrmFunctionalTestCase
{
private $product;
protected function setUp()
{
$this->useModelSet('ecommerce');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment