title: Validation to prevent parent referencing self as children
body: <p>I'm looking for a solution to prevent "parents" to add his self as "children".</p>
  
  <p>My Model looks like this:</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'
  end
  </code></pre>
  
  <p>Now I look for a solution to prevent things like this</p>
  
  <pre><code>parent = Category.create(name: "Parent")
  Category.new(name: "Children", parent_id: parent.id).valid? # should be =&gt; false
  </code></pre>