Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logical OR in doctrine2 getRepository->findBy()

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

like image 729
alwaysLearn Avatar asked Dec 26 '22 03:12

alwaysLearn


1 Answers

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:

like image 162
mohammad mohsenipur Avatar answered Jan 04 '23 17:01

mohammad mohsenipur