Answer the question
In order to leave comments, you need to log in
How to defeat Undefined index in UnitOfWork when saving inside postRemove?
Newbie on the subject. I write logs to a spreadsheet. When deleting an entity in the postRemove listner, I try to do this
$this->entityManager->persist($logRecord);
$this->entityManager->flush();
Symfony\Component\Debug\Exception\ContextErrorException: Notice: Undefined index: 0000000045c434420000000058164e1f in /var/www/vim/back/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:2917 Stack trace: #0 /var/www/vim/back/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php(522): Doctrine\ORM\UnitOfWork->getEntityIdentifier(Object(VimBundle\Entity\ViewArea))
#1 /var/www/vim/back/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php(452): Doctrine\ORM\Persisters\Collection\ManyToManyPersister->collectJoinTableColumnParameters(Object(Doctrine\ORM\PersistentCollection), Object(VimBundle\Entity\ViewArea))
#2 /var/www/vim/back/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php(71): Doctrine\ORM\Persisters\Collection\ManyToManyPersister->getDeleteRowSQLParameters(Object(Doctrine\ORM\PersistentCollection), Object(VimBundle\Entity\ViewArea))
#3 /var/www/vim/back/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(400): Doctrine\ORM\Persisters\Collection\ManyToManyPersister->update(Object(Doctrine\ORM\PersistentCollection))
#4 /var/www/vim/back/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php(356): Doctrine\ORM\UnitOfWork->commit(NULL)
#5 /var/www/vim/back/var/cache/dev/ContainerBahllwd/EntityManager_9a5be93.php(170): Doctrine\ORM\EntityManager->flush(NULL)
#6 /var/www/vim/back/src/VimBundle/EventListener/DoctrineEventListener/ChangesLogListener.php(447): EntityManager_9a5be93->flush()
Answer the question
In order to leave comments, you need to log in
The documentation for the event postRemove
explicitly states that this event is called inside the flush()
. So by calling $this->entityManager->flush()
internally postRemove
, you are actually spawning a potentially infinite loop, so "Undefined index" is really the least of your problems :)
It would be more correct to organize the work something like this:
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question