title: Self joins in Ruby on Rails
body: <p>As I already <a href="https://stackoverflow.com/questions/12554579/unable-to-join-self-joins-tables-in-rails">mentioned</a>, I have a model titled <code>Category</code></p>
  
  <pre><code>class Category &lt; ActiveRecord::Base
    belongs_to :parent, :class_name =&gt; "Category"
    has_many :children,  :class_name =&gt; "Category", :foreign_key =&gt; "parent_id"
    has_many :products
    attr_accessible :description, :title, :parent
  
  end
  </code></pre>
  
  <p>I need to select all <strong>child</strong> <code>Categories</code> that have a certain <strong>parent</strong> <code>Category</code> with a certain title:</p>
  
  <pre><code>Category.where(:category=&gt;{'parents_categories'=&gt;{:title=&gt;'tea'}}) #wrong
  </code></pre>
  
  <p>It's not working as I need. It's not working at all, actually:</p>
  
  <pre><code>Category Load (0.5ms)  SELECT `categories`.* FROM `categories` WHERE `parent`.`title` = 'tea'
  ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'parent.title' in 'where clause': SELECT `categories`.* FROM `categories`  WHERE `parent`.`title` = 'tea'
  </code></pre>
  
  <p>I did a research but found nothing. How do I solve it?</p>
  
  <p><strong>UPDATE</strong>:
  I have a need to create a scope in <code>Category</code> model which will allow me to make a call: <code>Category.of_tea</code> (exactly) and will return all <strong>children</strong> categories that belong to a <strong>parent</strong> <code>Category</code> with title '<code>tea</code>'.</p>