title: Rails models has_many
body: <p>Im starting to learn rails today and not quite sure how this would work:</p>
  
  <p>Lets say I have a Company, the company may have many subsidiaries.</p>
  
  <p>A subsidiary is a Company. 
  A company cannot be its own subsi
  diary for obvious reasons.</p>
  
  <p>A subsidiary cannot have a subsidiary that is also a subsidiary of the company</p>
  
  <p>So a subsidiary can also have subsidiaries, so its unlimitedly nested</p>
  
  <p>what im also not sure about below is that a subsidiary is a company</p>
  
  <pre><code>class Company &lt; ActiveRecord::Base
      has_many :subsidiaries
  end
  class Subsidiary &lt; ActiveRecord::Base
      belongs_to :companies
  end
  </code></pre>
  
  <p>Im sure this is so wrong, just putting something in here</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Ok, so I followed the instructions below like this:</p>
  
  <pre><code>class Company &lt; ActiveRecord::Base
      validates   :name, presence: true
      belongs_to :company
      has_many :subsidiaries, foreign_key: 'company_id', class_name: 'Company'
  end
  </code></pre>
  
  <p>In one of my templates:</p>
  
  <pre><code>&lt;% @companies.each do |company| %&gt;
      &lt;li&gt;&lt;%= link_to  "#{company.name} #{company.subsidiaries.length &gt; 0 ? "(#{company.subsidiaries.length} subsidiaries)" :"" }", company_path(@company, :id =&gt; company.id) %&gt;&lt;/td&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>Now this is show wrong, what happens is that the Ones with subsidiaries shows they have no subsidiaries and the ones who are subsidiaries shows they have subsidiaries, SO basicly its showing its parent's now, its "children"</p>
  
  <p>ANy idea why this happens?</p>