I seeked for an answer but anything in my particular case. I need to join contintionnally table with Doctrine 2, depends on value of a field I have to join on two different foreign keys, here my code :
$qb = $this->entityManager->createQueryBuilder();
$qb ->select('s')
->from('AppBundle:MyTable', 's')
->join('s.firstJoin', 'o')
->join('s.secondJoin', 'd')
->join('AppBundle:joinedView', 'view', Join::WITH,
"(CASE WHEN (d.secondJoinFK = 3)
THEN view.did = d.secondJoinFK
WHEN (d.secondJoinFK = 2)
THEN view.dvid = d.secondJoinFK END)")
->addSelect('d')
->where('s.endDate IS NULL');
However, with this request, Symfony tells me : [Syntax Error] line 0, col 203: Error: Expected Doctrine\ORM\Query\Lexer::T_ELSE, got '='
Moreover, I cannot use native query because I use PagerFanta for rendering template, and PagerFanta needs to have a ORM\Query on input and not ORM\NativeQuery or other.
Unfortunately, I do not have choice and must implement this request with these prerequisites.
Thanks by advance for your help,