Complex WHERE clauses using the PHP Doctrine ORM

后端 未结 7 1942
长发绾君心
长发绾君心 2020-12-13 09:15

I\'m using the PHP Doctrine ORM to build my queries. However, I can\'t quite seem to figure how to write the following WHERE clause using DQL (Doctrine Query Language):

7条回答
  •  半阙折子戏
    2020-12-13 09:49

    As it seems like you can't do complex queries using DQL, I wrote the following SQL to pass to the andWhere() method:

    $q->andWhere("(category1 IN $subcategory_in_clause
    OR category2 IN $subcategory_in_clause 
    OR category3 IN $subcategory_in_clause) AND TRUE");
    

    Note the "AND TRUE", a hack so that the parser wouldn't ignore the outer parentheses.

提交回复
热议问题