title: Rails SQL COUNT N+1 inefficiency
body: <p>I have a blog. On my index page, I pull in all blog posts. For each blog post, I count the number of comments on that post. This leads to an N+1 problem. My queries look as follows:</p>
  
  <pre><code>SELECT "blog_posts".* FROM "blog_posts" WHERE ("blog_posts"."published" = 't') ORDER BY published_at DESC
  SELECT "users".* FROM "users" WHERE ("users"."id" IN (1, 2, 3)) 
  SELECT COUNT(*) FROM "blog_comments" WHERE ("blog_comments".blog_post_id = 10)
  SELECT COUNT(*) FROM "blog_comments" WHERE ("blog_comments".blog_post_id = 9)
  SELECT COUNT(*) FROM "blog_comments" WHERE ("blog_comments".blog_post_id = 8)
  SELECT COUNT(*) FROM "blog_comments" WHERE ("blog_comments".blog_post_id = 2)
  SELECT COUNT(*) FROM "blog_comments" WHERE ("blog_comments".blog_post_id = 7) 
  </code></pre>
  
  <p>Is there a way in Rails to include the COUNT in the same way I include the users (SQL line 2)?</p>