title: has_one and has_many in same model. How does rails track them?
body: <p>I a little confused about how this work even if it works properly. I have a model that has two association to the same other model. </p>
  
  <p>Company has an owner and company has many employees of the class users. </p>
  
  <p>here is my company model:</p>
  
  <pre><code>class Company &lt; ActiveRecord::Base
    validates_presence_of :name
  
    has_many :employee, :class_name =&gt; 'User'
    has_one :owner, :class_name =&gt; 'User'
    accepts_nested_attributes_for :owner, :allow_destroy =&gt; true
  end
  </code></pre>
  
  <p>here is my user model:</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    include Clearance::User
    attr_accessible :lastname, :firstname #other attr are whitelisted in clearance gem
    validates_presence_of :lastname, :firstname
    belongs_to :company
  end
  </code></pre>
  
  <p>Now assuming I have 3 employee of this company including the owner. When I first create the company I set the owner to the employee with id 1 and the two others (2,3) are added to the employee list by setting their company_id (user.company=company). All three have their company_id set to the company id which we can assume is 1</p>
  
  <p>when I ask for company.owner, I get the right user and when I do company.employee, I get all three. </p>
  
  <p>If I change the owner to user 2, it removes user 1 from the employees automatically by setting it's company_id to nil. This is fine and if I add him back as a simple employee all is still good.</p>
  
  <p>How the heck does rails know which is which? What I mean is how does it know that an employee is owner and not just an employee? Nothing in the schema defines this. </p>
  
  <p>I have a feeling I should reverse the owner association and make company belong_to a user. </p>