title: Find model records by ID in the order the array of IDs were given
body: <p>I have a query to get the IDs of people in a particular order, say:
  <code>ids = [1, 3, 5, 9, 6, 2]</code></p>
  
  <p>I then want to fetch those people by <code>Person.find(ids)</code></p>
  
  <p>But they are always fetched in numerical order, I know this by performing:</p>
  
  <pre><code>people = Person.find(ids).map(&amp;:id)
   =&gt; [1, 2, 3, 5, 6, 9]
  </code></pre>
  
  <p>How can I run this query so that the order is the same as the order of the ids array? </p>
  
  <p>I made this task more difficult as I wanted to only perform the query to fetch people once, from the IDs given. So, performing multiple queries is out of the question.</p>
  
  <p>I tried something like:</p>
  
  <pre><code>ids.each do |i|
    person = people.where('id = ?', i)
  </code></pre>
  
  <p>But I don't think this works.</p>