php - Symfony 5 - Semantical *** Error has no field or association named category.id

one text

Solution:

Try this:

public function displayOne(Category $category): array
{
    return $this->createQueryBuilder('c')
        ->andWhere('c.category = :category')
        ->setParameter('category', $category)
        ->setMaxResults(3)
        ->getQuery()
        ->getResult();
}

Or alternatively:

public function displayOne(): array
{
    return $this->createQueryBuilder('c')
        ->join('c.category', 'cat')
        ->andWhere('cat.id = :category')
        ->setParameter('category', 1)
        ->setMaxResults(3)
        ->getQuery()
        ->getResult();
}

The three parts selector c.category.id is just not going to work.

Source