Doctrine - As you ask WHERE cond1 AND (cond2 OR cond3)

When using Doctrine in a Symfony project, I came into a situation where I needed to apply a condition and then one of the following two conditions (which are both subqueries). I know the functions andWhere () and orWhere (), but I am having problems using them to create things like: WHERE cond1 AND (cond2 OR cond3)

+3
source share
3 answers

You can do this using DQL:

$models = Doctrine::getTable('ModelName')
    ->findByDql(
        'field_one = ? AND (field_two = ? OR field_three = ?)',
        array('cond_1','cond_2', 'cond_3')
    );

Thus, models will represent Doctrine_Collection with all elements found.

+2
source

for cond2 OR cond3, where

where cond1 and where cond2 or where cond3

I hope this helps you.

0

, -

... where cond1 andWhere (cond2 orWhere cond3)

work? Or regardless of the actual syntax. Feel free to tell me if I am wrong and I will remove it and leave in the corner;)

0
source

Source: https://habr.com/ru/post/1721656/


All Articles