Search code examples
symfonygroup-bydql

Symfony DQL Error on join + group by : Expected litteral, got 'BY'


I have two entities, Product and Keyword with a ManyToMany relation. I want to get all keywords and for each keyword the number of occurences it is linked to a product.

I'm using DQL. I first tried to use the jointable in my query but I found that it wasn't a good way of doing it. I followed this post, which is quite similar to what I want to achieve, but I get an error.

Here is my query :

SELECT k.id, k.value, count(p.id)
FROM App\AppBundle\Entity\Keyword k
JOIN App\AppBundle\Entity\Product p
GROUP BY p.id

Here is the error I get :

Error : Expected Literal, got 'BY'.

I am unable to see what's wrong.
Any advice is welcomed. Thanks.


Solution

  • when you join, you do so using the property name, so it is probably something like

    SELECT k.id, k.value, count(p.id)
    FROM App\AppBundle\Entity\Keyword k
    JOIN k.products p
    GROUP BY p.id