Created
September 11, 2013 20:58
-
-
Save rsl/6529686 to your computer and use it in GitHub Desktop.
this seems to do what i want
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.find_by_ordered_ids(ids) | |
order_by = ['case'] | |
ids.each_with_index do |id, index| | |
order_by << "WHEN id='#{id}' THEN #{index}" | |
end | |
order_by << 'end' | |
where(id: ids).order(order_by.join(' ')) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment