title: Rails: Query with association?
body: <p>I want to gather all posts where <code>created_at &lt;= Time.now</code>, <code>status = 0</code> and <code>dislikes &lt; 3</code>. <code>created_at</code> and <code>status</code> is columns in the <code>Post</code> table, but <code>Dislike</code> is its own table. How can I access the amount of dislikes within the query (<code>Post</code> and <code>Dislike</code> is "connected" through has_many)?</p>
  
  <p>I have this now, and it works:</p>
  
  <pre><code>@posts = Post.where("created_at &lt;= ? AND status = ?", Time.now, 0).order("created_at DESC")
  </code></pre>
  
  <p>How can I include the amount of dislikes in the query?</p>
  
  <p>(The Dislike table consist of <code>:post_id</code> and <code>:user_id</code> and I can get the amount of dislikes on a post by writing <code>@post.dislikes.count</code>)</p>