score:3

Accepted answer

You have to use getReference to get an object of website class without adding a query, then just link it as a parameter

$em = $this->getDoctrine()->getManager();

$website    = $em->getReference('AndreiStatisticsBundle:Website', 3);

$repository = $em->getRepository('AndreiStatisticsBundle:Visit');

$qb = $repository->createQueryBuilder('v')
    ->select('SUM(v.counter) AS views, v.createdAt AS day')
    ->where('v.website = :website')
    ->setParameter('website', $website)
    ->groupBy('v.createdAt');

$visits = $qb->getQuery()->getScalarResult();

score:0

Use innerJoin of leftJoin

$em = $this->getDoctrine()->getManager();

$repository = $em->getRepository('AndreiStatisticsBundle:Visit');

$qb = $repository->createQueryBuilder('v')
    ->select('SUM(v.counter) AS views, v.createdAt AS day')
    ->innerJoin('v.website', 'w')
    ->where('w.id = :website_id')
    ->setParameter('website_id', 3)
    ->groupBy('v.createdAt');

$visits = $qb->getQuery()->getScalarResult();

Related Query

More Query from same tag