I have a entity with a price property in a form. In a update i want cancel the changes for this entity.
This is my code in preUpdate event listener:
if($entityManager->contains($entity)) {
$entityManager->detach($entity);
$uow = $entityManager->getUnitOfWork();
$meta = $entityManager->getClassMetadata(get_class($entity));
$uow->recomputeSingleEntityChangeSet($meta, $entity);
}
But in a test a get this error message:
1) WebFactory\PriceListBundle\Tests\Entity\PriceListTest::testCreateProduct Doctrine\ORM\ORMInvalidArgumentException: Entity WebFactory\Bundle\PriceListBundle\Entity\PriceList@000000005f6fc4da0000000028ff97b1 is not managed. An entity is managed if its fetched from the database or registered as new through EntityManager#persist