可以使用symfony上的表单对一个或另一个字段发出请求
$user_test = $em->getRepository("AppBundle:UserTest")->findOneBy([
'hash' => $data->user_data->hash,
'code' => $data->user_data->hash],
);
得到WHERE hash = 'foo' OR code = 'foo'
您必须在实体UserTest存储库中定义方法
// UserTestRepository.php
public function getUserTestByHashOrCode($hash, $code){
return $this->createQueryBuilder('u')
->where('hash = :hash')
->orWhere('code = :code')
->setParameter('hash', $hash)
->setParameter('code', $code)
->getQuery()
->getOneOrNullResult();
和
$user_test = $em->getRepository("AppBundle:UserTest")->getUserTestByHashOrCode($data->user_data->hash, $data->user_data->hash);