title: How to do has_many and has_one association in same model?
body: <p>I need to do two associations in the same model. Where:</p>
  
  <p><strong>Team</strong> <code>has_many</code> <strong>User</strong>
  Now, I want that <strong>Team</strong> <code>has_one</code> <strong>Leader</strong></p>
  
  <p>This "Leader" will be a User</p>
  
  <p>Im trying to use <code>has_one throught</code> but I think that association isn't work.</p>
  
  <p>Leader.rb</p>
  
  <pre><code>class Leader &lt; ActiveRecord::Base
  belongs_to :user
  belongs_to :team
  </code></pre>
  
  <p>Team.rb</p>
  
  <pre><code>class Team &lt; ActiveRecord::Base
  has_one :user, through: :leader
  end
  </code></pre>
  
  <p>User.rb</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
  
  belongs_to :team
  has_one :captain
  
  end
  </code></pre>
  
  <p>and the get following error around line 27:</p>
  
  <pre><code>NoMethodError in TeamsController#create
  
  26 def create
  
  **27 @team = current_user.teams.create(team_params)**
  
  28 @team.save
  
  29 respond_with(@team)
  
  30 current_user.update(team_id: @team.id)
  </code></pre>