Save new onFlush object

I try to use the onFlush event in the Doctrine to save a new object, but when I try to save it, it leads to an infinite loop. Here is what I do in Listener:

$countusers = $em->getRepository('DankeForumBundle:NotificationUser')->countNotificationsByDeal($entity);
if ($countusers > 0) {
  $notification = new NotificationAction();
  $notification->setDeal($entity);
  $notification->setDatepost(new \DateTime());
  $notification->setNotificationtype(NotificationAction::TYPE_TOP_DEAL);
  // $em is set to EntityManager
  $em->persist($notification);
  // $uow ist set to UnitOfWork
  $uow->computeChangeSet($em->getClassmetadata('Danke\ForumBundle\Entity\NotificationAction'), $notification);
}

I know that I get a loop when I fill in the onFlush event, but I do not! I just figured out a new set of changes, as it says in the documentation.

Can someone tell me where the problem is?

EDIT: Maybe it is interesting that I am sure it worked a few days ago, but I can’t change anything (which, as I know, cannot be true;)) ...

+5
source share
1 answer

I had similar problems with onFlush Event. Please change

$em->persist($notification);

to

$uow->persist($notification);

Please try this and let me know if this works now.

+3

All Articles