I was hoping I could get some help optimizing this query for a rails site:
Vacation
has_many :departures
has_many :photos
Departure
belongs_to :vacation
Photo
belongs_to :vacation
I need to find a list of vacations ordered and displayed by departure. So if a vacation has two departures, it should show up in the list twice (once for each departure).
@dates = Departure.find(:all,
:order => "start_at",
:include => [{:vacation => :photos}],
:conditions => ["vacations.duration > 1 AND start_at > ?", Time.now])
The issue is that I THEN need to collect all the future departures for each vacation, which results in a new query for each departure listed.
Any ideas on how to better accomplish this?