Doctrine findBy with OR condition

后端 未结 4 1647
夕颜
夕颜 2021-02-04 23:54

Is it possible to use OR statement in Doctrine findBy() method? I know that given array is interpreted as case1 AND case2... Like this

4条回答
  •  余生分开走
    2021-02-05 00:28

    If you are using MongoDB and need more complex queries, like "less than" linked together with OR, but cannot use a query builder, this also works with this syntax:

       ->findBy(array(
                    '$or' => array(
                        array('foo' => array('$lt' => 1234)),
                        array('$and' => array(
                            array('bar' => 45678),
                            array('baz' => array('$lt' => 89013))
                        ))
                    )
        ));
    

    Or as a solution for your question:

       ->findBy(array(
                    '$or' => array(
                        array('status' => 1),
                        array('status' => 2),
                        array('status' => 3),
                    )
        ));
    

提交回复
热议问题