title: Get the parent of a child in a has_many relationship?
body: <p>Im creating a RoR app to manage a basketball league. I have two tables: <code>teams</code> &amp; <code>games</code>. Its set up that each team has many games. Each row in <code>games</code> contains two foreign keys; one for home team, and one for away team. I have the following code to list the data in the <code>games</code> table:</p>
  
  <pre><code>&lt;% @games.each do |game| %&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;%= game.home_team_id %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= game.away_team_id %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= game.home_team_score %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= game.away_team_score %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= game.date %&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>However, the first two parts dont work, presumably because is used the format when calling an objects child. But here, im trying to call the child's parent (game.home_team_id)</p>
  
  <p>How do you get the parent of a child?</p>
  
  <p>Here's my Game model:</p>
  
  <pre><code>class Game &lt; ActiveRecord::Base
    belongs_to :team, :foreign_key =&gt; "home_team"
    belongs_to :team, :foreign_key =&gt; "away_team"
    has_many :stats
  
  end
  </code></pre>