pass array of conditions to doctrine expr()->orx() method

后端 未结 5 1736
忘掉有多难
忘掉有多难 2020-12-25 10:56

I need to construct DQL with a QueryBuilder like this

[QUERY]... AND WHERE e.type = x OR e.type = Y OR e.type = N [...]

I hav

5条回答
  •  伪装坚强ぢ
    2020-12-25 11:07

    I hope so, then I found this :

    $conditions = array('e.type = x', 'e.type = Y', 'e.type = N');
    $orX = $qb->expr()->orX();
    
    foreach ($conditions as $condition) {
        $orX->add($condition);
    }
    
    $qb->add('where', $orX);
    

    Using @meze suggestion, you can simplify the code and replace the foreach statement with:

    $orX->addMultiple($conditions);
    

提交回复
热议问题