Rails where condition and order
<p>Knowing that by default Rails orders data by ID, how can I order by ids given to the where clause?</p>

<pre><code>ids = Bookmark.where(user_id: 7).order(created_at: :desc).pluck(:company_id)
</code></pre>

<p>Result:</p>

<blockquote>
  <p>[146, 140, 128, 4, 2]</p>
</blockquote>

<p>Now, when I try to get the companies in the same order from <code>ids</code></p>

<pre><code>Company.where(id: ids).pluck(:id)
</code></pre>

<p>Result:</p>

<blockquote>
  <p>[2, 4, 128, 140, 146]</p>
</blockquote>

<p><strong>Expected Result</strong>:</p>

<blockquote>
  <p>[146, 140, 128, 4, 2]</p>
</blockquote>

<p>My pretended result will be the same in both cases (same order).
The companies should be returned in the same order that the Bookmarks on that company where created.</p>