title: Has_many, belongs_to with multiple foreign keys
body: <p>I'm trying to attribute matches to a club through a has_many, belongs_to relationship. However, in matches, I need to set the club either as a home_team or away_team. To solve this I'm using two foreign_keys.</p>
  
  <pre><code>class Club &lt; ActiveRecord::Base
    has_many :matches
  end
  
  class Match &lt; ActiveRecord::Base
    belongs_to :home_team, class_name: 'Club', foreign_key: 'home_team_id'
    belongs_to :away_team, class_name: 'Club', foreign_key: 'away_team_id'
  end
  </code></pre>
  
  <p>This sets the clubs nicely on the match using home_team_id and away_team_id. </p>
  
  <p>However, I can't access all of a club's matches through Club.matches. </p>
  
  <pre><code>ERROR:  column matches.club_id does not exist
  </code></pre>
  
  <p>How can I change my relationship so I can do this?</p>