I have two Models, Programme and Event, a programme has many events. I need to find the programmes which have an event with a specfic date.
@programmes = Programme.joins(:events).where(:events => {:date => params[:date]}).uniq
This works correctly. But when using
programme.events
it of course gets all events associated with a programme, how can I get just the events that match the criteria in original statement
The easiest way is to create a method on programme
You would then call this:
You could also add a scope to the Event class, but this is likely easier to understand.