Reinier Reinier - 9 months ago 39
Ruby Question

Join with where clause that filters out specific records, rails active record

I am making a sports application with leagues and events, the events contain a

, the leagues have a
and an
. How can I get all the event with starting date today together with the league name and country.

I tried:

League.joins(:events).where(events: {event_start:})

But this returns all the leagues that have an event today, when I then try to access the events from that specific league, all events are included and not only the ones that are being plaid today.


Start with Events and include relevant League to avoid N+1 problem.