Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if entity was already persisted to EntityManager in Symfony2

In Symfony2, is it possible to check if particular entity was already persisted and is present in the EntityManager?

I'm working with some data import and some of the records might be exact duplicates. I'm doing bulk inserts, i.e., calling flush() only after certain amount of entities were persisted. So, I need to check if the entity I am trying to persist is not in the EntityManager already.

like image 982
Vitalius Avatar asked Jul 16 '14 08:07

Vitalius


1 Answers

yes you shoud use the unitOfWork http://phpdox.de/demo/Symfony2/classes/Doctrine_ORM_UnitOfWork.xhtml#isEntityScheduled

$uow = $this->getDoctrine()->getManager()->getUnitOfWork()
$exist =  $uow->isEntityScheduled(  $entity );
like image 110
pietro Avatar answered Sep 20 '22 22:09

pietro