在我的数据库中,我有由字段"type“定义的数据,比如:
const TYPE_ONE = 'one';
const TYPE_TYPE = 'two';我想返回由这两个常量而不是所有常量定义了"type“值的所有结果。( like (空)类型)。
似乎不支持OR运算符。
我的代码:
return $this->getMyEntityRepository()->findBy([
'type' => MyEntity::TYPE_ONE || MyEntity::TYPE_TWO
]);发布于 2019-07-04 18:14:34
OR operator is supported,但从理论上讲,您应该在存储库中为这种查询创建一个方法。
存储库:
class MyEntityRepository extends ServiceEntityRepository
{
public function findByType()
{
return $this->createQueryBuilder('r')
->andWhere('r.type IN (:types)')
->setParameter('types', [MyEntity::TYPE_ONE, MyEntity::TYPE_TWO])
->getQuery()
->getResult()
;
}
}控制器:
return $this->getMyEntityRepository()->findByType();您还可以为要查找的类型指定参数。
https://stackoverflow.com/questions/56885402
复制相似问题