Or on symfony findOneBy



可以使用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);

相关内容

  • 没有找到相关文章

最新更新