Q:

Get Courses depending on another relation

I have a two relations called Course and School. 
Course also has a datetime field open_date. 
I want to return all course where the school tier is not 1, and whithin a certain date. 
I want some rails code like this:
Course.includes(:school).where("school.tier <> ?  AND open_date between ?  and ?", 1 , date1, date2)

A:

You were almost there:
Course.joins(:schools).where("schools.tier <> ?  AND schools.open_date between ?  and ?", 1 , date1, date2)

The joins clause will eliminate the Courses without School associated.  
(if doesn't work, try with joins(:school))

