createQueryBuilder('a') ->select('COUNT(a)') ->where('a.categoryId = :categoryId') ->setParameters(array('categoryId' => $categoryId)) ->getQuery() ->getSingleScalarResult(); } }