I found this problem myself and wanted to publish my solution. Since you are creating a queryBuilder outside of an EntityManager instead of an EntityRepository, you need a from statement. The error occurs when there is no from statement or if the from statement does not work (from what needs to be done to join it so that it is happy). EntityRepository will take care of this for you when using it.
public function myFindAll() { $genres = $this->_em->createQueryBuilder('g') //from statement here ->from('GenreEntityClass', 'g') // leftJoin because I need all the genre ->leftJoin('g.films', 'f') ->addSelect('COUNT(f)') ->groupBy('g') ->getQuery() ->getArrayResult(); // $genres contains all the genres and the associated movies return ($genres); }
source share