title: How do I select only the associated objects in a Rails "where" query?
body: <p>I have a model Category, which has_many Products, and a Product in turn has_many Categories. When a user searches for a Category, I'd like to return the products of the matching Categories without losing my Arel object. Here's what I have so far:</p>
  
  <pre><code>Category.where("upper(title) like ?", search_term.upcase).map {|category| category.products}.flatten
  </code></pre>
  
  <p>This does the trick of returning the products, but of course what I have is an array and not Arel. I can get as far as adding an <code>:includes(:products)</code> clause, so I do indeed get the products back but I still have them attached to their categories. How do I adjust my query so that all I get back is an Arel that only addresses products?</p>