title: rails where() sql query on array
body: <p>I'll explain this as best as possible. I have a query on user posts:</p>
  
  <p><code>@selected_posts = Posts.where(:category =&gt; "Baseball")</code></p>
  
  <p>I would like to write the following statement. Here it is in pseudo terms:</p>
  
  <p><code>User.where(user has a post in @selected_posts</code>)</p>
  
  <p>Keep in mind that I have a many to many relationship setup so <code>post.user</code> is usable.</p>
  
  <p>Any ideas?</p>
  
  <p>/EDIT</p>
  
  <pre><code>@posts_matches = User.includes(@selected_posts).map{ |user|
  
        [user.company_name, user.posts.count, user.username]
  
      }.sort
  </code></pre>
  
  <p>Basically, I need the above to work so that it uses the users that HAVE posts in selected_posts and not EVERY user we have in our database.</p>