0

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.

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.