Doctrine2 LEFT JOIN unter 2 Bedingungen

Ich versuche, ein "Produkt" anhand der ID zu finden, und bin unter zwei Bedingungen am "Foto" beteiligt: ​​dem Gebietsschema und dem aktiven Status.

Hier ist mein QueryBuilder:

$queryBuilder = $this->createQueryBuilder('p')
            ->select('p, photos, photoTranslation')
            ->leftJoin('p.photos', 'photos')
            ->leftJoin('photos.translations', 'photoTranslation')
            ->where('p.id = :id')
            ->andWhere('(photoTranslation.locale = :locale OR photoTranslation.locale IS NULL)')
            ->andWhere('(photoTranslation.active = :active OR photoTranslation.active IS NULL)')
            ->setParameters(array(
                'id' => $id
                'locale' => $this->getLocale(),
                'active' => true
             ));

Es funktioniert einwandfrei, wenn keine Fotos vorhanden sind oder wenn AKTIVIERTE Fotos vorhanden sind, jedoch nicht, wenn ein inaktives Foto vorhanden ist, da es keiner der beiden Bedingungen entspricht.

Wenn ich nur eine Bedingung verwende, zum Beispiel nur das Gebietsschema, funktioniert es einwandfrei:

$queryBuilder = $this->createQueryBuilder('p')
            ->select('p, photos, photoTranslation')
            ->leftJoin('p.photos', 'photos')
            ->leftJoin('photos.translations', 'photoTranslation')
            ->where('p.id = :id')
            ->andWhere('(photoTranslation.locale = :locale OR photoTranslation.locale IS NULL)')
            ->setParameters(array(
                'id' => $id
                'locale' => $this->getLocale()
             ));

Im Moment mache ich eine Schleife mit diesen Ergebnissen und deaktiviere alle inaktiven Fotos ... aber ich möchte eine saubere Möglichkeit, dies im QueryBuilder zu tun.

Ich habe auch versucht, die Bedingungen für die LEFT JOIN-Klausel festzulegen:

->leftJoin('photo.translations', 'phototTranslation', Doctrine\ORM\Query\Expr\JOIN::WITH, 'photoTranslation.locale = :locale AND photoTranslation.active = :active')

Das Foto wird jedoch immer zurückgegeben, auch wenn es inaktiv ist.

Antworten auf die Frage(1)

Ihre Antwort auf die Frage