jschouwstra
11/14/2017 - 7:21 PM

Get all games with their corresponding plays with plays higher than 0

Get all games with their corresponding plays with plays higher than 0

//For Symfony 3.2
    /**
     * @Route("/test", name="suggestion_test")
     *
     */
    public function getPlayedGames(Request $request)
    {
        $manager = $this->getDoctrine()->getManager();

        /** @var QueryBuilder $qb */
        $qb = $manager->createQueryBuilder();

        $query = $qb
            ->select('g.name, count(p.game) as plays')
            ->from(PlayLog::class, 'p')
            ->leftJoin('p.game', 'g')
            ->groupby('g.name')
            ->having('count(plays) > 0')
            ->getQuery();
        $results = $query->getResult();
        return $this->render('suggestion/show.html.twig', array(
            'suggestionList' => $results
        ));

    }