In symfony 5, with doctrine I want to create a request to select distinct type. So, I have made the following code:
/**
* @Route("/hometest", name="hometest")
*/
public function index2()
{
$lesservices = $this->getDoctrine()->getRepository(Services::class)->findAll();
$em = $this->getdoctrine()->getManager();
$query = $em->createQuery('SELECT distinct serv.souscategorie FROM App\Entity\Services serv');
$services = $query->getResult();
return $this->render('home/indextest.html.twig', array ('servicesliste' => $lesservices, 'distinctscat' => $query));
}
But, I am getting this error :
[Semantical Error] line 0, col 21 near 'souscategorie': Error: Invalid PathExpression. Must be a StateFieldPathExpression.
In fact, souscategorie is a relation field and if I put a string field at his place everything goes right.
Do I have to make a join request to have my souscategorie results ?
Thanks for your answers.