views:

177

answers:

3

While using Doctrine in a Symfony project I've come into the situation where I need to apply a condition and then one of two following conditions (which both happen to be sub-queries). I know of the andWhere() and orWhere() functions, but am having trouble using these to generate things like: WHERE cond1 AND ( cond2 OR cond3)

A: 

for the cond2 OR cond3 use wherein

where cond1 and wherein cond2 or wherein cond3

hopefully this gets you started

theraven
This seems to help with the subquery part, but doesn't seem to aid in adding the hierarchy to my AND / OR opperators, right?
mattfarmerdotnet
A: 

I haven't heard of this tool but shouldn't something like

... where cond1 andWhere (cond2 orWhere cond3)

work? Or whatever the actual syntax is. Feel free to tell me if I'm wrong and I'll delete it and slunk off in a corner ;)

RCIX
+1  A: 

You can do this whith DQL:

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

So $models will be a Doctrine_Collection with all found elements.

DerKlops