如何使用学说查询生成器编写以下内容?
SELECT
    registry.id ,
    registry.couple_id,
    registry.gift_id,
    Sum(purchase.amount) as totalContribution,
    gift.title,
    gift.price
FROM
    gift,
    registry
LEFT JOIN
    purchase ON purchase.registry_id = registry.id
WHERE
    registry.gift_id = gift.id
    AND registry.couple_id = 1 
GROUP BY
    registry.couple_id,
    registry.gift_id
我试过了:
$qb = $this->createQueryBuilder('g') //gift
    ->from('\BBB\GiftBundle\Entity\Registry', 'reg')
    ->select('g.id , g.title, g.description, g.price, g.imageMedium')
    ->addSelect('SUM(p.amount) as totalContribute')
    ->leftJoin('\BBB\GiftBundle\Entity\Purchase', 'p', 'ON','reg.id = p.registry')
    ->where('reg.gift = g.id')
    ->AndWhere('reg.couple = :coupleID')
    ->orderBy('reg.id','DESC')
    ->groupBy('reg.couple')
    ->groupBy('reg.gift')
    ->setParameter('coupleID', $coupleID);
但它给了我以下错误:
[语义错误] 第 0 行,第 178 列,靠近“p ON reg.id =”:错误:标识变量 BBB\GiftBundle\Entity\Purchase 用于连接路径表达式,但之前未定义。