title: rails has_one through a collection
body: <p>I'll start by pasting the relevant code and then I'll explain later what I am trying to do</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    has_many :compus, :dependent =&gt; :destroy
    has_many :companies, :through =&gt; :compus
  end
  
  class Company &lt; ActiveRecord::Base
    has_many :compus, :dependent =&gt; :destroy
    has_many :employees, :through =&gt; :compus, :source =&gt; :user
    has_one  :owner, :through =&gt; :compus, :source =&gt; :user, :conditions =&gt; { :owner =&gt; true }
  end
  
  class Compu &lt; ActiveRecord::Base
    belongs_to :company
    belongs_to :user
  end
  </code></pre>
  
  <p>The compus table has the following columns (copied from the migration)</p>
  
  <pre><code>create_table :compus do |t|
    t.references :company
    t.references :user
    t.string     :job_title
    t.boolean    :owner, null: false, default: false
  
    t.timestamps
  end
  </code></pre>
  
  <p>So as you can see, I have a user who can create n companies and have jobs at n companies, having a job at a company does not mean he's the owner..</p>
  
  <p>What I would like to get is:</p>
  
  <p>user.companies        #=> The companies the user has created, or have jobs at (I worry about filtering results later)</p>
  
  <p>company.employees     #=> All the users that have jobs at this company (through compus)</p>
  
  <p>company.owner         #=> The one user that has originally created the company (or another one if transferred later)</p>
  
  <p>So I added the following spec before I wrote the code above.</p>
  
  <pre><code>it "has one owner" do
    company = Factory(:company)
    user    = Factory(:user)
  
    company.should respond_to(:owner)
  
    user.companies &lt;&lt; company
  
    company.owner.should === user
  end
  </code></pre>
  
  <p>but I'm getting the following error:</p>
  
  <pre><code>ActiveRecord::HasOneThroughCantAssociateThroughCollection:
         Cannot have a has_one :through association 'Company#owner' where the :through association 'Company#compus' is a collection. Specify a has_one or belongs_to association in the :through option instead.
  </code></pre>
  
  <p>So how can resolve this problem without adding more columns to the companies table, it would be easier if I added <em>owner_id</em> on the companies table but that would lead to duplications in the database, usually if a user created a company it means that he works at it</p>
  
  <p>Another question while I'm at it, How can I easily access the :job_title that is on the compus table through the association?</p>