Create an array of objects ordered based on the attribute of the child class
I have a class Job
:
class Job < ActiveRecord::Base
has_many :stops
end
Stop
class has attribute datetime :arrival time
What is a concise way to get an array of all jobs ordered by early arrival time at related stops?
eg.
If job_1 has two stops, one with an arrival time of 4pm and one with an arrival time of 5pm.
And job_2 has two stops, one with an arrival time of 3pm and one with an arrival time of 6pm.
I need array: [job_2, job_1]
I can achieve this, but in a cumbersome way that involves looping and temporarily storing values.
Thank!
+3
source to share