计算imagefk等于的记录总数? 在symfony

I have a table in the db where I can count the total number of records in the table where imagefk is equal to the parameter given. Here is a possible structure of the table

id | reviews | bookname | imagefk
1  |  1      | xyz      | null
2  |  1      | xyz      | 53
3  |  1      | xyz      | 53

Using below to return the total count of reviews where imagefk is equal to the parameter given, it returns all records instead of the three rows

public function getAllImagesAction(String imagefk)
    {
    $entityManager = $this->getDoctrine()->getManager();
            $qb = $entityManager->createQueryBuilder();
            $qb->select('count(e.reviews)');
            $qb->from('xxxBundle:Books','e')
                    ->add('where', 'e.imagefk = imagefk'); // making the parameter dynamic and to pull from the url routing.yml file
            $count = $qb->getQuery()->getSingleScalarResult();

my challenge with the above query is that the where clause does not count 2 records based on this parameter

instead it counts 3 records. Please what could be wrong. Kindly assist

You need to join your entity with Images entity and then you can add where clause on image id like

$entityManager = $this->getDoctrine()->getManager();
    $qb = $entityManager->createQueryBuilder();
    $qb->select('count(b.reviews)')
       ->from('xxxBundle:Books','b')
       ->join('b.imagerating','i')
       ->where('i.id = :id')
       ->setParameter('id', 53);       
$count = $qb->getQuery()->getSingleScalarResult();