Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.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
Doctrine orm 通过关系找到了新实体?_Doctrine Orm - Fatal编程技术网

Doctrine orm 通过关系找到了新实体?

Doctrine orm 通过关系找到了新实体?,doctrine-orm,Doctrine Orm,我有一个句柄代码 if ($this->request->isMethod('POST') && $valid) { $em = $this->getDoctrine()->getManager(); $formData = $form->getData(); $staffValue = $formData['staff']; $campaignDetai

我有一个句柄代码

if ($this->request->isMethod('POST') && $valid) {
            $em = $this->getDoctrine()->getManager();
            $formData = $form->getData();
            $staffValue = $formData['staff'];
            $campaignDetailFilter = $modelCampaignDetail->getRepository()->countDataByCampaignDetailId($formData['campaignDetail']);
            $total         = count($campaignDetailFilter);
            $totalStaff = count($formData['staff']);

            foreach ($campaignDetailFilter as $valDetailId) {
                $detailDataEntity = $modelDetailData->getEntity($valDetailId['id']);
                $batchSize = $total / $totalStaff;
                $i = 0;
                foreach ($staffValue as $staffVal) {
                    $detailDataEntity->setStaff($staffVal);
                    $em->persist($detailDataEntity);
                    if (($i % $batchSize) === 0) {
                        $em->flush();
                        $em->clear();
                    }
                    ++$i;
                }
                $em->flush();
                $em->clear();
            }
        }

但当我给$I=0时,它会得到一个错误:通过关系找到了一个新实体…该实体未配置为级联实体的持久化操作

您应该删除$em->clear()


谢谢兄弟。我还有一个问题。请帮帮我。例如,在变量“$staffVal”中,我有两个雇员(id:2,id:3)。对于那两名雇员,我有十行要求平分。但当我:$detailDataEntity->setStaff($staffVal)时,它就被设置了(id:3)。我做错了。请帮帮我@n2k您可以尝试:$employee=$em->getRepository(Employees::class)->find($staffVal)$detailDataEntity->setStaff($employee);
if (($i % $batchSize) === 0) {
     $em->flush();
}