I've got a event table with title and description of an event, and i've got a eventInstance table where the dates and venues of an event are stored. So it's a one to n relation: one event can have many instances.
What i'm trying now is to select only the most current event instance for an event. In SQL the query is:
select e.id, e.title, ei.start_date
from event e
LEFT join event_instance ei on ei.id =
(SELECT id FROM event_instance ei where ei.event_id = e.id ORDER BY start_date asc, start_time asc LIMIT 1)
ORDER BY start_date asc, start_time asc LIMIT 20;
I'm trying to rewrite the sql command in dql. So far i've got this:
SELECT e, ei
FROM AppBundle:Event e LEFT JOIN e.eventInstances ei WITH ei =
(SELECT a FROM AppBundle:EventInstance a WHERE a.event = e ORDER BY a.startDate asc, a.startTime asc)
My problem is, there's no LIMIT command in dql, so i cannot limit the subquery to give me one result. So the error i'm getting when executing this query is:
SQLSTATE[21000]: Cardinality violation: 7 ERROR: more than one row returned by a subquery used as an expression
Is there any way i can make this work?