0

The phpcr odm documentation seems to be quite clear on that point, but I can't manage to make it. Here the raw mysql equivalent expected:

SELECT (foo, bar, baz) FROM table
WHERE (foo = 'foo') AND bar = 'bar' OR (baz = 'baz' OR baz = 'bazinga')

I tried something like this.

$qb->from()
->document('Detours\MainBundle\Document\Product', 'p');

$qb->where()
->andX()
->eq()
->field('p.foo')
->literal('foo');

$qb->andWhere()
    ->eq()
    ->field('p.bar')
    ->literal('bar')
    ->end();


$qb->where()
   ->eq()
   ->field('p.baz')
   ->literal('baz');
$qb->orWhere()
  ->eq()
  ->field('p.baz')
  ->literal('baz');
loicb
  • 587
  • 2
  • 6
  • 24
  • 1
    What do you mean by "imbricate"? I'm sure it's not "arrange (scales, sepals, plates, etc.) so that they overlap like roof tiles." http://www.merriam-webster.com/dictionary/imbricate – DavidPostill Mar 24 '15 at 14:52
  • Sure, it's not what I mean. Thank you for the quick english lesson :). – loicb Mar 24 '15 at 15:51
  • So what did you mean? ;) – DavidPostill Mar 24 '15 at 15:52
  • I edited the title, it should be better. – loicb Mar 24 '15 at 15:54
  • Are you aware that you have a "where" in the middle, after andWhere for p.bar = bar? that will eliminate the previous where clause afaik. Try something like $qb->where()->orX()->andX()->eq()...->eq()->...->end()->orX()... – dbu Mar 25 '15 at 07:43

2 Answers2

1

The original poster created a github issue for this now https://github.com/doctrine/phpcr-odm/issues/619

dbu
  • 1,497
  • 9
  • 8
0

Just to help futher visitors, here the correct syntax.

(All credits to dantleech and dbu)

 $qb->where()
->andX()
    ->eq()->field('p.foo')->literal('foo')->end()
    ->orX()
        ->eq()->field('p.bar')->literal('bar')->end()
        ->orX()
            ->eq()->field('p.baz')->literal('baz')->end()
            ->eq()->field('p.baz')->literal('bazinga');
loicb
  • 587
  • 2
  • 6
  • 24