franco-allemand
franco-allemand

Reputation: 13

Doctrine2 LEFT JOIN exception

I've got a problem with Symfony/Doctrine2 doing SQL statement with two entites:

$qb = $this->getEntityManager()->createQueryBuilder();
    $qb->select('s')
    ->from('basecomProductionWorkflowBaseBundle:SubprocessData', 's')
    ->leftJoin('basecomProductionWorkflowBaseBundle:ReleaseDay', 'r', Expr\Join::WITH, 'r.id = s.releaseDay')
    ->where(
            $qb->expr()->andX(
                    $qb->expr()->eq('r.date', ':date'),
                    $qb->expr()->isNotNull('r.edition')
            )
    )
    ->setParameter('date', $date);

I got the following error message:

[Semantical Error] line 0, col 124 near 'r WITH r.id =': Error: Identification Variable basecomProductionWorkflowBaseBundle:ReleaseDay used in join path expression but was not defined before.

PS: Both tables have no relation to each other (it's a workaround fixing another problem). I've tested the same statement in phpmyadmin.

Upvotes: 1

Views: 1062

Answers (2)

smoreno
smoreno

Reputation: 3540

¿What Expr class are you using? I choose incorrectly the Expr class some days ago and throw me same exception.

Try:

use Doctrine\ORM\Query\Expr;

Upvotes: 0

Elnur Abdurrakhimov
Elnur Abdurrakhimov

Reputation: 44851

It should be:

->leftJoin('s.releaseDay', 'r')

You could also simplify the conditions this way:

->where('r.date = :date')
->andWhere('r.edition IS NOT NULL')

or:

->where('r.date = :date AND r.edition IS NOT NULL')

Upvotes: 1

Related Questions