我尝试了以下东西:
$subQuery = $this->createQueryBuilder('teachingEvent')->select('teachingEvent.id')
->leftJoin('teachingEvent.timeTableEntry', 'timeTableEntry')
->leftJoin('timeTableEntry.course', 'course')
->where('course.school = :school' )
->andWhere('teachingEvent.date >= :fromDate')
->andWhere('teachingEvent.date <= :toDate')
->setParameters(array(':fromDate' => $from, ':toDate' => $to, ':school' => $school))
->getDQL();
$query = $this->createQueryBuilder('teachingEvent')
->update()
->set('teachingEvent.schoolFreeDate', ':schoolFreeDate')
->where('teachingEvent.id IN ' . $subQuery)
->getQuery();
return $query->getResult();
当我转储子查询时,我得到这个:
"从 AppBundle\Entity\Teaching Event 教学事件中选择 teachingEvent.id 左加入教学事件.时间表条目时间表条目左加入时间表条目.课程 其中 course.school = :学校和教学事件.日期>= :从日期和教学事件.日期 <= :toDate
对我来说,现在似乎应该工作 - 但我收到以下错误消息
[语法错误] 第 0 行,第 136 行:错误:预期的文字,得到"教学事件">
如何找到错误?
您也可以先从第一个查询构建器获取对象,然后执行所需的更新来执行相同的操作
$teachingEvents = $this->createQueryBuilder('teachingEvent')
->select('teachingEvent')
->leftJoin('teachingEvent.timeTableEntry', 'timeTableEntry')
->leftJoin('timeTableEntry.course', 'course')
->where('course.school = :school' )
->andWhere('teachingEvent.date >= :fromDate')
->andWhere('teachingEvent.date <= :toDate')
->setParameters(array(':fromDate' => $from, ':toDate' => $to, ':school' => $school))
->getQuery()
->getResult();
foreach($teachingEvents as $teachingEvent){
$teachingEvents->setSchoolFreeDate($someDate);
$em->persist($teachingEvents);
/* $em->flush(); flush here or after loop */
}
$em->flush();