我在Doctrine中遇到了findOneBy()
函数的问题。我想在该函数中使用OR
条件。这是我的示例代码:
$data = $this->getDoctrineRepo(Employee::class)
->findOneBy(['nik' => $code, 'void' => 0]);
这可以实现吗?如果有,请举个例子。感谢。
答案 0 :(得分:2)
您可以尝试使用 QueryBuilder
$query = $this->createQueryBuilder('u')
->select('u')
->where('u.nik = :nik OR u.void = :void')
->setParameter('nik', $code)
->setParameter('void', 0)
;
$result = $query->getQuery()->getOneOrNullResult();
答案 1 :(得分:1)
试试这个;
$data = $this->getDoctrineRepo(Employee::class)
->findOneBy([
'$or' => [
['nik' => $code],
['void' => 0]
]
]
);