Doctrine QueryBuilder 无法解析 EntityField 中的 WHERE X

Doctrine QueryBuilder can't parse WHERE X IN EntityField

当我尝试 select 集合中包含数字的所有实体时,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 是多对多关系。

我做错了什么?

ORM Magic 没有像我预期的那样工作。您不能将 ManyToMany 字段用作数组,如果左侧部分是整数,则解析器需要进行简单比较。要获得预期的结果,您必须加入 Field 并根据 id 过滤此结果。

$qb->innerJoin("f0.offices", 'be')->where("be.id = ${companyId}");