2013-05-18 38 views
4

如何编写查询像doctrine2逻辑或doctrine2 getRepository-> findBy()

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

我发现像

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

但我认为这是和..请建议me 谢谢

+0

这将帮助:HTTPS://doctrine-orm.readthedocs.org/en/latest /reference/working-with-objects.html?highlight=getRepository –

+0

@NiladriDas我已经看过那里,但不能得到我想要的 – alwaysLearn

+0

请参阅条件运算符http://docs.doctrine-project.org/projects/doctrine-mongodb -odm/en/latest/reference/query-builder-api.html#conditional-operators你可以用'in'来查看这个页面http://stackoverflow.com/questions/9259089/doctrine-findby-with-或条件 –

回答

10

试试这个

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

如果传递值的数组学说将查询转换成WHERE场(..)查询自动: