Chaining orX in Doctrine2 query builder

后端 未结 2 1030
醉梦人生
醉梦人生 2020-12-16 13:58

I have to dynamically add OR expressions to the query builder returned by getListQueryBuilder, right after adding a where clause. I ca

相关标签:
2条回答
  • 2020-12-16 14:37

    You can check this solution:

    $orX = $builder->expr()->orX();
    foreach($ORs as $or) {
        $orX->add($or);
    }
    $builder->andWhere($orX);
    
    0 讨论(0)
  • 2020-12-16 14:50

    I stumbled on the same problem and tried :

    $builder->andWhere($builder->expr()->orX($ORs));
    

    but it does not work since orX calls "return new Expr\Orx(func_get_args());" internally and you end up with something like array(array(or1, or2))

    having looked at the API however i figured you can do this:

    $builder->andWhere($builder->expr()->orX()->addMultiple($ORs));
    

    OR do use $ORs table at all but issue:

    $orx = $builder->expr()->orX();
    $orx->add($builder->expr()->like("t.name", 'my name'));
    $orx->add($builder->expr()->like("t.description", 'desc'));
    $builder->andWhere($orx);
    
    0 讨论(0)
提交回复
热议问题