gpt4 book ai didi

mysql - Symfony 查询生成器使用子查询进行更新

转载 作者:行者123 更新时间:2023-11-29 10:27:29 24 4
gpt4 key购买 nike

我尝试了以下内容:

 $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();

当我转储子查询时,我得到:

"SELECT teachingEvent.id FROM AppBundle\Entity\TeachingEvent teachingEvent LEFT JOIN teachingEvent.timeTableEntry timeTableEntry LEFT JOIN timeTableEntry.course course WHERE course.school = :school AND teachingEvent.date >= :fromDate AND teachingEvent.date <= :toDate

对我来说,似乎现在应该可以工作 - 但我收到以下错误消息

[Syntax Error] line 0, col 136: Error: Expected Literal, got '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();

关于mysql - Symfony 查询生成器使用子查询进行更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48034654/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com