Skip to content

Commit

Permalink
Merge branch 'DDC-958' into 2.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
beberlei committed Jan 23, 2011
2 parents 7350d85 + b63babc commit 0893d2e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/Doctrine/ORM/Persisters/BasicEntityPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
Doctrine\ORM\Query,
Doctrine\ORM\PersistentCollection,
Doctrine\ORM\Mapping\MappingException,
Doctrine\ORM\Mapping\ClassMetadata;
Doctrine\ORM\Mapping\ClassMetadata,
Doctrine\ORM\Events,
Doctrine\ORM\Event\LifecycleEventArgs;

/**
* A BasicEntityPersiter maps an entity to a single table in a relational database.
Expand Down Expand Up @@ -695,6 +697,14 @@ public function refresh(array $id, $entity)
}

$this->_em->getUnitOfWork()->setOriginalEntityData($entity, $newData);

if (isset($this->_class->lifecycleCallbacks[Events::postLoad])) {
$this->_class->invokeLifecycleCallbacks(Events::postLoad, $entity);
}
$evm = $this->_em->getEventManager();
if ($evm->hasListeners(Events::postLoad)) {
$evm->dispatchEvent(Events::postLoad, new LifecycleEventArgs($entity, $this->_em));
}
}

/**
Expand Down
21 changes: 21 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,27 @@ public function testGetReferenceWithPostLoadEventIsDelayedUntilProxyTrigger()
$this->assertTrue($reference->postLoadCallbackInvoked);
}

/**
* @group DDC-958
*/
public function testPostLoadTriggeredOnRefresh()
{
$entity = new LifecycleCallbackTestEntity;
$entity->value = 'hello';
$this->_em->persist($entity);
$this->_em->flush();
$id = $entity->getId();

$this->_em->clear();

$reference = $this->_em->find('Doctrine\Tests\ORM\Functional\LifecycleCallbackTestEntity', $id);
$this->assertTrue($reference->postLoadCallbackInvoked);
$reference->postLoadCallbackInvoked = false;

$this->_em->refresh($reference);
$this->assertTrue($reference->postLoadCallbackInvoked, "postLoad should be invoked when refresh() is called.");
}

/**
* @group DDC-113
*/
Expand Down

0 comments on commit 0893d2e

Please sign in to comment.