当我尝试通过查询构建器执行查询时出现错误[Syntax Error] line 0, col 81: Error: Expected Literal, got 'NULL'
$qb = $this->createQueryBuilder('r')
->select('r')
->where('r.query = :query')
->setParameter('query', $query)
->andWhere('r.lang = NULL')
;
return $qb->getQuery()->getOneOrNullResult();
r.lang
字段定义为:
/**
* @var integer
*
* @ORM\ManyToOne(targetEntity="\BW\LocalizationBundle\Entity\Lang")
* @ORM\JoinColumn(name="lang_id", referencedColumnName="id")
*/
private $lang;
请帮助解决错误
答案 0 :(得分:12)
检查NULL值时,表达式应为
->andWhere('r.lang IS NULL')