diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index dc5c882f866..53f5ff37f9b 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1796,6 +1796,10 @@ private function doPersist($entity, array &$visited) $this->addToIdentityMap($entity); $this->entityStates[$oid] = self::STATE_MANAGED; + + if ($class->isChangeTrackingDeferredExplicit()) { + $this->scheduleForDirtyCheck($entity); + } break; case self::STATE_DETACHED: diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7629Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7629Test.php index 7a007447fcf..25dfa946804 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7629Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7629Test.php @@ -31,6 +31,20 @@ public function testClearScheduledForSynchronizationWhenCommitEmpty(): void self::assertFalse($this->_em->getUnitOfWork()->isScheduledForDirtyCheck($entity)); } + + /** + * @group GH-8231 + */ + public function testPersistAfterRemoveSchedulesForSynchronization(): void + { + $entity = $this->_em->find(GH7629Entity::class, 1); + + $this->_em->remove($entity); + + $this->_em->persist($entity); + + self::assertTrue($this->_em->getUnitOfWork()->isScheduledForDirtyCheck($entity)); + } } /**