Logical OR in doctrine2 getRepository->findBy()

2019-05-07 01:18发布

How can write query like in doctrine2

SELECT * from table where field = value1 or field = value2

I found something like

 $em->getRepository('myentitity')
           ->findBy(
               array('field' => 'value1','field'=>'value2'),        // $where 
             );

But I think it is AND .. Please suggest me Thanks

1条回答
我欲成王,谁敢阻挡
2楼-- · 2019-05-07 01:46

try this

  $em->getRepository('myentitity')
       ->findBy(
           array('field' =>array( 'value1','value2'))        // $where 
         );

If you pass an array of values Doctrine will convert the query into a WHERE field IN (..) query automatically:

查看更多
登录 后发表回答