views:

424

answers:

1

I need to sort an array of ActiveRecord objects by the value in one of the columns but am unsure of how to do this.

Example, I have an Schedule model that has a Duration column. I then have two arrays of Schedule objects OriginalList and NewList. I want to sort each of those lists by Duration. I think that I'm looking for something like: -

Schedule.find(:all, 
              :conditions => "schedule_id IN (select schedule_id from 
                                              #{array.each.schedule_id}",
              :order => 'duration')

However, this doesn't look right at all! Not even in SQL!!

Any hints on how to do this would be appreciated.

A: 

Oops. Ignore that! By writing it down I figured out what I actually wanted to do.

Schedule.find(:all, :conditions => "schedule_id in ("1", "2", "3"), :order => "duration")

where the 1, 2, 3 can be generated from the array prior to calling.

Blame it on Friday afternoon! :D

Urf