title: ActiveRecord has two association
body: <p>What is the best way to achieve a has two association with activerecord?  </p>
  
  <p>I have a Team and Game models.  Each Team will have_many games <code>@team.games</code>.  A Game will have two teams <code>@game.hosting_team</code> and <code>@game.opposing_team</code>.</p>
  
  <p>I started out with two <code>belongs_to/has_one</code> associations but then <code>@team.games</code> would only return their home games.</p>
  
  <p>The other option I can think of is using a HABTM and use a validator to ensure there are only records.  The only thing missing is keeping track of the home team.  It seems like I need a has many through association but I'm not exactly sure...</p>
  
  <p>Thanks for your help. </p>
  
  <p>This is an example of how the two has_many associations look.  The problem here is I would have to call <code>team.games</code> and <code>team.opponents</code> to get a full list of their games</p>
  
  <pre><code>class Team &lt; ActiveRecord::Base
    has_many :games
    has_many :opponents, :class_name =&gt; "Team"#, :foreign_key =&gt; ""
  end
  
  class Game &lt; ActiveRecord::Base
    belongs_to :team, :class_name =&gt; "Team" #, :foreign_key =&gt; "team_id"
    belongs_to :opponent, :class_name =&gt; "Team" #, :foreign_key =&gt; "opponent_id"
  end
  </code></pre>
  
  <p>I'd like something like this but this obviously isn't how belongs_to works.</p>
  
  <pre><code>class Team &lt; ActiveRecord::Base
    has_many :games
  end
  
  class Game &lt; ActiveRecord::Base
    belongs_to :hosting_team
    belongs_to :opposing_team
  end
  </code></pre>
  
  <p>My desired api would look like this.</p>
  
  <pre><code>@team.games # return all games home or away
  @game.hosting_team # Team
  @game.opposing_team # Team
  </code></pre>