Doctrine findBy with OR condition

后端 未结 4 1656
夕颜
夕颜 2021-02-04 23:54

Is it possible to use OR statement in Doctrine findBy() method? I know that given array is interpreted as case1 AND case2... Like this

4条回答
  •  佛祖请我去吃肉
    2021-02-05 00:12

    I know that this is old question. Anyways, it's possible to use Criteria for the complex queries (in Doctrine 2 at least):

    $criteria = new \Doctrine\Common\Collections\Criteria();
    $criteria
      ->orWhere($criteria->expr()->contains('domains', 'a'))
      ->orWhere($criteria->expr()->contains('domains', 'b'));
    
    $groups = $em
      ->getRepository('Group')
      ->matching($criteria);
    

提交回复
热议问题