title: Rails avoid N+1 query problem working with external and internal data
body: <p>I have the following array coming from an external source :</p>
  <pre><code>documents = ['Doc Name 1', 'Doc Name 2', 'Doc Name 3', ...]
  </code></pre>
  <p>I want to loop through the array, and find details about the documents in my db (model <code>Doc</code>) if it exists.</p>
  <pre><code>documents.each do |document|
    puts Doc.find_by_name(document).details if Doc.find_by_name(document)
  end
  </code></pre>
  <p>Of course this code works, but how can I avoid the N+1 query problem?</p>