title: Rails ActiveRecord Join
body: <p>I'm using rails and am trying to figure out how to use ActiveRecord within the method to combine the following into one query:</p>
  
  <pre><code>def children_active(segment)
    parent_id = Category.select('id').where('segment' =&gt; segment)
    Category.where('parent_id'=&gt;parent_id, 'active' =&gt; true)
  end
  </code></pre>
  
  <p>Basically, I'm trying to get sub categories of a category that is designated by a unique column called segment.  Right now, I'm getting the id of the category in the first query, and then using that value for the parent_id in the second query.  I've been trying to figure out how to use AR to do a join so that it can be accomplished in just one query.</p>