title: Rails 4 - how to compare two collection of objects and pick the same ones?
body: <p>I am running 2 (sometimes 3) searches, like:</p>
  
  <pre><code>first_search  = Company.where('...') # returns 2 objects
  second_search = Company.where('...') # returns 4 objects
  </code></pre>
  
  <p>Let's say that <code>first_search</code> contains objects with these IDs:</p>
  
  <pre><code>10
  20
  </code></pre>
  
  <p><code>second_search</code> contains</p>
  
  <pre><code>10
  30
  40
  50
  </code></pre>
  
  <p>I would like to save to another variable (say <code>results</code>) objects with the same IDs from <code>first_search</code> and <code>second_search</code>, thus <code>results</code> would only contain the object with ID:</p>
  
  <pre><code>10
  </code></pre>
  
  <p>How to do this?</p>
  
  <p>Thank you/</p>
  
  <p><strong>EDIT:</strong>
  the intersection is working based on the <code>id</code> column, right? Would be there a way to make the intersection work on a different column? Say <code>name</code>?</p>