并在 LEFT JOIN 中加入 Doctrine

AND in LEFT JOIN with Doctrine

我怎样才能像这样在 LEFT JOIN 中添加 AND SELECT * FROM photo LEFT JOIN liked_photo lp on photo.id = lp.photo_id AND lp.user_id = 6 其中 photo.is_public = 1 ?

`{`
    `return $this->createQueryBuilder('photo')`
        `->leftJoin("photo.likedPhotos", "lp", "photo.id = lp.Photo")`
        `->addSelect('lp')`
        `->where('photo.is_public = 1')`
        `->orderBy('photo.uploaded_at', 'DESC')`
        `->getQuery();`

}

试试 :

return $this->createQueryBuilder('photo')
        ->leftJoin("photo.likedPhotos", "lp", Join::WITH, "photo.id = lp.Photo AND lp.user_id = 6")
        ->addSelect('lp')
        ->where('photo.is_public = 1')
        ->orderBy('photo.uploaded_at', 'DESC')
        ->getQuery();

参见学说文档:https://www.doctrine-project.org/projects/doctrine-orm/en/2.9/reference/query-builder.html#line-number-5775ab09aefa638b14c776a733b4b61d2e324b74-43