ruby on rails - Need help optimizing this database query -


i hoping optimizing query rails site:

vacation has_many :departures has_many :photos  departure belongs_to :vacation  photo belongs_to :vacation 

i need find list of vacations ordered , displayed departure. if vacation has 2 departures, should show in list twice (once each departure).

@dates = departure.find(:all,                          :order => "start_at",                          :include => [{:vacation => :photos}],                         :conditions => ["vacations.duration > 1 , start_at > ?", time.now]) 

the issue need collect future departures each vacation, results in new query each departure listed.

any ideas on how better accomplish this?

you don't have limit on query, wouldn't have need pulled memory? have array every future departure each vacation want display.

so use array have.

vacation_id = 3 # or whatever - in loop. @dates_for_vacation = @dates.select{|d| d.vacation_id == vacation_id} 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -