Is it possible to construct a scope like this
User.where(:id => [5,4,3,2,7,1000] )
in a way, that
a) the results are in the order of the ids passed. (This is the simple part, since you can just load the records, and sort the result accordingly)
b) the result is not an array but a scope in itself (The tricky part 😉
Update: Solutions that only work on MySQL are welcome.
I can think of two ways to do it:
(1) Put an order column in the database.
(2) Use raw SQL and a custom ORDER BY clause like so:
I’m not sure how portable that is.