I have an array of item ID’s, item_ids.
I’m passing this array into an ActiveRecord query to retrieve the corresponding items from the database: Item.where(:id => item_ids)
Is there any way to get the items returned in the same order as passed in via the item_ids array?
If it makes a difference, I’m on Ruby on Rails 3.0.12 with PostgreSQL as my database.
You can get the database to do the sorting and avoid multiple
indexcalls, you just have to remember that an SQL ORDER BY orders by an expression, not a column: