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:

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: