我尝试了以下内容:
$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 \ TeachingEvent进行选择SELECT TeachingEvent.id \ Entity \ TeachingEvent TeachingEvent左联接教导事件.timeTableEntry timeTableEntry左联接timeTableEntry.course课程WHERE course.school =:
对我来说,现在应该可以工作了-但我收到以下错误消息
[语法错误]行0,列136:错误:预期文字,获取了'teachingEvent'
如果有人可以找到该错误,那就更好了。
感谢你!
新年快乐 ;)!
最佳答案
您还可以通过先从第一个查询构建器获取对象,然后进行所需的更新来执行相同操作
$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();