1

I basically want to do this SQL statement:

SELECT * FROM Table1
JOIN Table2
ON (
Table2.ID = Table1.THIS_ID
OR
Table2.ID = Table1.THAT_ID
)

Using createQueryBuilder and NOT createQuery.

Is it possible? All the examples I can find only deal with a single condition and don't tackle the issue of AND/OR within a join.

Thanks.

Adi
  • 742
  • 7
  • 22

2 Answers2

0

You can try something like that (in a repository for instance):

$qb = $this->createQueryBuilder('t1');
$qb->join('t1.table2', 't2', Expr\Join::WITH, 't2.id = t1.thisId OR t2.id = t1.thatId');
...
bjuice
  • 291
  • 1
  • 8
0

You can do it like this:

$qb->leftJoin(
         'u.Phonenumbers', 
         'p', 
         Expr\Join::WITH, 
         $qb->expr()->orx(
                 $qb->expr()->eq('t.this_id', 't1.id'),
                 $qb->expr()->eq('t.this_id', 't1.id')
         )
)
Udan
  • 5,429
  • 2
  • 28
  • 34
  • There bit I have trouble with here, is the u.Phonenumbers part. e.g. I just want to join Table2, like you do in normal SQL. I don't want to deal with a bit of it and if Phonenumbers is a mapping, I don't have a mapping between the two tables. – Adi Oct 23 '13 at 11:26