title: Rails foreign key to the same table
body: <p>I have a rails app that contains workorders. I'm going to be loading workorders from another system.  That system uses a single table for parent and child workorders.</p>
  
  <p>I added a field to the workorders table called parent_id</p>
  
  <p>Is this the right coding in the Workorder model?</p>
  
  <pre><code> class ParentWorkorder
     belongs_to :parent, class_name =&gt; "Workorder"
     belongs_to :child, class_name =&gt;  "Workorder", :foreign_key =&gt; "parent_id"
   end
  </code></pre>
  
  <p>Or would you advise against doing this - and instead create a child workorder table?  I think that might make it harder to integrate with the other system.</p>
  
  <p>Any guidance would be greatly appreciated!</p>