Skip to content

Commit

Permalink
DDC-1230 - Fix bug where UnitOfWork does not set STATE_REMOVE when ca…
Browse files Browse the repository at this point in the history
…lling EntityManager#remove() on an entity
  • Loading branch information
beberlei committed Jun 28, 2011
1 parent 5afc097 commit 551f6d0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/Doctrine/ORM/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ public function scheduleForDelete($entity)
if ($this->isInIdentityMap($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.
}

Expand All @@ -999,6 +999,7 @@ public function scheduleForDelete($entity)
}
if ( ! isset($this->entityDeletions[$oid])) {
$this->entityDeletions[$oid] = $entity;
$this->entityStates[$oid] = self::STATE_REMOVED;
}
}

Expand Down
34 changes: 34 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,40 @@ public function testBasicOneToOne()
$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()
{
$user = new CmsUser;
Expand Down

0 comments on commit 551f6d0

Please sign in to comment.