Let\'s say I have two models: Course and ScheduledCourse.
The Course model has a name attribute.
course has_many :scheduled courses scheduled_courses :belongs_to
Try...
ScheduledCourse.joins(:course).order('course.name')
If this doesn't work, you may need to call .all
before your joins condition, like so:
ScheduledCourse.all.joins(:course).order('course.name')
Like luacassus said, this answer can help; I think the syntax in that answer is pre-Arel (ActiveRecord 3), but it'll get the job done. Hope that helps!
EDIT:
As mentioned by @FellowStranger, the correct syntax nowadays seems to be
ScheduledCourse.joins(:course).order('courses.name')