1
0
mirror of synced 2025-01-20 07:21:40 +03:00

DDC-1230 - Fix bug where UnitOfWork does not set STATE_REMOVE when calling EntityManager#remove() on an entity

This commit is contained in:
Benjamin Eberlei 2011-06-28 21:37:53 +02:00
parent 5afc097527
commit 551f6d05d9
2 changed files with 36 additions and 1 deletions

View File

@ -984,7 +984,7 @@ class UnitOfWork implements PropertyChangedListener
if ($this->isInIdentityMap($entity)) { if ($this->isInIdentityMap($entity)) {
$this->removeFromIdentityMap($entity); $this->removeFromIdentityMap($entity);
} }
unset($this->entityInsertions[$oid]); unset($this->entityInsertions[$oid], $this->entityStates[$oid]);
return; // entity has not been persisted yet, so nothing more to do. return; // entity has not been persisted yet, so nothing more to do.
} }
@ -999,6 +999,7 @@ class UnitOfWork implements PropertyChangedListener
} }
if ( ! isset($this->entityDeletions[$oid])) { if ( ! isset($this->entityDeletions[$oid])) {
$this->entityDeletions[$oid] = $entity; $this->entityDeletions[$oid] = $entity;
$this->entityStates[$oid] = self::STATE_REMOVED;
} }
} }

View File

@ -140,6 +140,40 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertFalse($user2->address instanceof \Doctrine\ORM\Proxy\Proxy); $this->assertFalse($user2->address instanceof \Doctrine\ORM\Proxy\Proxy);
} }
/**
* @group DDC-1230
*/
public function testRemove()
{
$user = new CmsUser;
$user->name = 'Guilherme';
$user->username = 'gblanco';
$user->status = 'developer';
$this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_NEW, $this->_em->getUnitOfWork()->getEntityState($user));
$this->_em->persist($user);
$this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_MANAGED, $this->_em->getUnitOfWork()->getEntityState($user));
$this->_em->remove($user);
$this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_NEW, $this->_em->getUnitOfWork()->getEntityState($user));
$this->_em->persist($user);
$this->_em->flush();
$id = $user->getId();
$this->_em->remove($user);
$this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_REMOVED, $this->_em->getUnitOfWork()->getEntityState($user));
$this->_em->flush();
$this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_NEW, $this->_em->getUnitOfWork()->getEntityState($user));
$this->assertNull($this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $id));
}
public function testOneToManyOrphanRemoval() public function testOneToManyOrphanRemoval()
{ {
$user = new CmsUser; $user = new CmsUser;