1
0
mirror of synced 2024-12-13 06:46:03 +03:00

[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:
beberlei 2009-12-07 22:10:40 +00:00
parent 59c6449076
commit 845c85552e
3 changed files with 26 additions and 3 deletions

View File

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

View File

@ -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 */
@ -100,6 +120,10 @@ class LifecycleCallbackTestEntity
*/ */
public $value; public $value;
public function getId() {
return $this->id;
}
/** @PrePersist */ /** @PrePersist */
public function doStuffOnPrePersist() { public function doStuffOnPrePersist() {
$this->prePersistCallbackInvoked = true; $this->prePersistCallbackInvoked = true;

View File

@ -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');