Doctrine QueryBuilder无法解析WHERE X IN EntityField

问题描述 投票:0回答:1

[当我尝试选择集合中所有数字的实体时,Doctrine会引发异常:

[Syntax Error] line 0, col 70: Error: Expected =, <, <=, <>, >, >=, !=, got 'IN'

QueryBuilder以这种方式使用:

$this->getEntityManager()->createQueryBuilder()->select('f0')->from(Factory::class, 'f0')->where("${companyId} IN f0.offices");

[Facotry::offices是ManyToMany关系。

我在做什么错?

php postgresql doctrine-orm doctrine doctrine-query
1个回答
0
投票

ORM Magic无法正常运行。您不能将ManyToMany字段用作数组,并且如果左侧部分是整数,则解析器期望进行简单比较。要获得预期的结果,您必须加入Field并在id上过滤此结果。

$qb->innerJoin("f0.offices", 'be')->where("be.id = ${companyId}");
© www.soinside.com 2019 - 2024. All rights reserved.