Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将新实体持久化到刷新_Php_Doctrine Orm_Doctrine - Fatal编程技术网

Php 将新实体持久化到刷新

Php 将新实体持久化到刷新,php,doctrine-orm,doctrine,Php,Doctrine Orm,Doctrine,我试图使用条令中的onFlush事件来持久化一个新实体,但在尝试持久化时,它会导致无限循环。以下是我在侦听器中所做的操作: $countusers=$em->getRepository('DankeForumBundle:NotificationUser')->countNotificationsByDeal($entity); 如果($countusers>0){ $notification=newnotificationaction(); $notification->setDeal($en

我试图使用条令中的
onFlush
事件来持久化一个新实体,但在尝试持久化时,它会导致无限循环。以下是我在侦听器中所做的操作:

$countusers=$em->getRepository('DankeForumBundle:NotificationUser')->countNotificationsByDeal($entity);
如果($countusers>0){
$notification=newnotificationaction();
$notification->setDeal($entity);
$notification->setDatepost(new\DateTime());
$notification->setNotificationtype(NotificationAction::TYPE_TOP_DEAL);
//$em设置为EntityManager
$em->persist($notification);
//$uow设置为UnitOfWork
$uow->computeChangeSet($em->getClassmetadata('Danke\ForumBundle\Entity\NotificationAction'),$notification);
}
我知道当我在
onFlush
事件中刷新时,我会得到一个循环,但我没有这样做!我只计算文档中所述的新变更集


有人能告诉我问题出在哪里吗?

我在onFlush事件中遇到了类似的问题。请换

$em->persist($notification);

$uow->persist()
将使UnitOfWork了解新实体,并安排插入。 调用
$uow->computeChangeSet()
是必要的,以收集应该由条令的持久器插入的数据

$uow = $em->getUnitOfWork();
$uow->persist($notification);

$metadata = $em->getClassMetadata(get_class($notification));
$uow->computeChangeSet($metadata, $notification);