title: How can I optimize this Query with Rails
body: <p>I have an array of book ids and I need to iterate each and save the number of comments for each in a Hash (@book_comments) that will have the book_id as the key and the number of comments for that book as a value. Book has many comments, comment belong to books.</p>
  
  <pre><code>@book_ids.map {|id| @book_comments[id] = Book.find(id).comments.size}
  </code></pre>
  
  <p>This will hit the DB with these two queries for the amount of ids I have on my array.</p>
  
  <pre><code>SELECT `books`.* FROM `books` WHERE `books`.`id` = ? LIMIT 1
  SELECT COUNT(*) FROM `comments` WHERE `comments`.`book_id` = ?
  </code></pre>
  
  <p>Surely there's a better way. 
  If you know, please teach me.
  Thank you.</p>