title: Database One-to-Many with two foreign key fields in Laravel
body: <p>I have been trying to define some Database schema to use the laravel framework. I want to model a Football match. The first step I wanted to do is to define the Entity Relationship diagram, but I found this (which I thought would be quite trivial) to be confusing in some aspects.</p>
  
  <p>First, the obvious approach is to say that a Match is related with two Teams, and a Team is related to any number of Matches. So, we would have a "Many to Many" relationship.</p>
  
  <p>But the implementation of a many to many relation is to have two tables and an intermediate table to relate both entities. I think this would be too much, when I know that a Match will always have two Teams and simply having two columns (local_id and visitant_id) with foreign keys to the Teams table would be enough. Plus, I want to be able to do:</p>
  
  <pre><code>Match::find(1)-&gt;local() or Match::find(1)-&gt;visitant();
  </code></pre>
  
  <p>So, thinking on this I am implementing a "One to Many" relation, but with this I have another issue. To retrieve all the matches a Team has played I would like to do:</p>
  
  <pre><code>Team::find(1)-&gt;matches(); 
  </code></pre>
  
  <p>But I cannot do this because I can only specify one key column when defining the matches() method in eloquent (by default it would be team_id, but it should be visitant_id and local_id).</p>