diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index b36ad7fb8..fd7f69cc5 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1630,6 +1630,7 @@ class UnitOfWork implements PropertyChangedListener case self::STATE_REMOVED: // Entity becomes managed again unset($this->entityDeletions[$oid]); + $this->addToIdentityMap($entity); $this->entityStates[$oid] = self::STATE_MANAGED; break; diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 97f60f859..02c818e1f 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -229,6 +229,25 @@ class UnitOfWorkTest extends \Doctrine\Tests\OrmTestCase $this->setExpectedException('InvalidArgumentException'); $this->_unitOfWork->lock(null, null, null); } + + /** + * @group DDC-3619 + * @group 1338 + */ + public function testRemovedAndRePersistedEntitiesAreInTheIdentityMapAndAreNotGarbageCollected() + { + $entity = new ForumUser(); + $entity->id = 123; + + $this->_unitOfWork->registerManaged($entity, array('id' => 123), array()); + $this->assertTrue($this->_unitOfWork->isInIdentityMap($entity)); + + $this->_unitOfWork->remove($entity); + $this->assertFalse($this->_unitOfWork->isInIdentityMap($entity)); + + $this->_unitOfWork->persist($entity); + $this->assertTrue($this->_unitOfWork->isInIdentityMap($entity)); + } } /**