There is one-2-many relation between Property and Reservation. Property has column called ‘nr_of_bookings’. I need DQL that will retrieve only the properties that has COUNT(Reservation) less than Property.nr_of_bookins.
An example: Some Property has nr_of_bookings = 3 . If it has 5 Reservations related, it will not be retrieved. But if it has 2 related Reservations, it will be retrieved.
I tried numerous combinations, but I miss something obviosly. I posted similar question
here , but it is better to start from scratch. Thanks.
Have you tried:
EDIT: The above is for Doctrine 2. For Doctrine 1.2, looking at your code, I’m guessing your
HAVINGclause is referencing something that’s not in a group by or the result of an aggregate function. Try something like this:You’re grouping by
p.idsoSUM(p.nr_of_bookings)will be equal top.nr_bookings.From the MySQL documentation: