title: Rails: Get all associated models from has-many association
body: <p>I need to get all associated models from the other associated model, on which I want to run query first.</p>
  
  <p>For example, I got Post model and Tag model. I need to get all Posts, which associated with some Tags.
  There's no problem, if I have only one Tag – just call 'tag.posts', but if I have more, then one Tag – for example, I need to do somethink like:</p>
  
  <pre><code>Post.where(id: PostTag.where(tag_id: some_ids).pluck(:category_id).uniq)
  </code></pre>
  
  <p>I belive that Rails have a built-in solution. So, anybody knows it?</p>