I have an array of IDs:
array_of_ids = [5, 14, 2, 20]
I want to find all records of a class Klass
that have an ID in the array, and keep the order they appear in the array.
Klass.where(id: array_of_ids)
returns the correct array, but it is unordered. Is there any way to keep the original order in the array? I can't simply use the order
method because it is not an attribute but a method call. I also need to keep it as an active record relation.