title: How can I add a virtual "count" column to a select query in rails?
body: <p>I have a post model, and post has_many :comments, :as => :commentable (polymorphic).  I am looking for a way that I can fetch all posts, and have a virtual attribute on the record which will display how many comments belong to that post.</p>
  
  <p>I was thinking that I could just do:</p>
  
  <pre><code>Post.select("posts.*, count(comments.id) as post_comments").joins(:comments)
  </code></pre>
  
  <p>However, that returns only one record, with post_comments set to ALL comments in the entire database, not just those belonging to the record...</p>