4

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

alwaysLearn
  • 6,882
  • 7
  • 39
  • 67
  • This will help :https://doctrine-orm.readthedocs.org/en/latest/reference/working-with-objects.html?highlight=getRepository – Niladri Das May 18 '13 at 06:49
  • @NiladriDas I already had a look there but cant get what I want – alwaysLearn May 18 '13 at 06:58
  • see condition operator http://docs.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/reference/query-builder-api.html#conditional-operators you can use `in` for this and see this page http://stackoverflow.com/questions/9259089/doctrine-findby-with-or-condition – mohammad mohsenipur May 18 '13 at 06:58

1 Answers1

10

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:

mohammad mohsenipur
  • 3,218
  • 2
  • 17
  • 22