title: Rails multiple associations between two models
body: <p>I have Flight, Person, and Glider models in a Rails 3 app. I've defined custom relationships because I need more than one foreign key referencing a Person from the flights table. Associations work but ONE-WAY only.</p>
  
  <pre><code>class Flight &lt; ActiveRecord::Base
    belongs_to :pilot, :class_name =&gt; "Person"
    belongs_to :instructor, :class_name =&gt; "Person"
    belongs_to :towplane_pilot, :class_name =&gt; "Person"
    belongs_to :airplane_instructor, :class_name =&gt; "Person"
  
    belongs_to :glider
    belongs_to :rep_glider, :class_name =&gt; "Glider"
  
    belongs_to :departure_airfield, :class_name =&gt; "Airfield"
    belongs_to :arrival_airfield, :class_name =&gt; "Airfield"
  
  end
  
  class Glider &lt; Aircraft
    has_many :flights
    has_many :replaced_flights, :foreign_key =&gt; "rep_glider_id", :class_name =&gt; "Flight"
  end
  
  class Person &lt; ActiveRecord::Base
    has_many :flights, :foreign_key =&gt; "pilot_id", :class_name =&gt; "Flight"
    has_many :instructed_flights, :foreign_key =&gt; "instructor_id", :class_name =&gt; "Flight"
    has_many :towed_flights, :foreign_key =&gt; "towplane_pilot_id", :class_name =&gt; "Flight"
    has_many :instructed_towing_flights, :foreign_key =&gt; "airplane_instructor_id", :class_name =&gt; "Flight"
  end
  </code></pre>
  
  <hr>
  
  <hr>
  
  <pre><code>####What works#####
  Flight.first.glider
  Flight.first.rep_glider
  Flight.first.pilot 
  Flight.first.instructor 
  Flight.first.towplane_pilot
  Flight.first.airplane_instructor
  
  Glider.first.flights 
  Glider.first.replaced_flights    
  
  ####What doesn't work#### ----&gt; NoMEthodError 'match'
  Person.first.flights
  Person.first.instructed_flights
  Person.first.towed_flights.
  Person.first.instructed_towing_flights
  </code></pre>
  
  <p>I'm almost there, but I don't understand how <code>Glider.first.flights</code> does work when <code>Person.first.flights</code> doesn't.</p>
  
  <p>UPDATE: Associations with 'Airfield' works... so I'm clueless as to why it doesn't work with 'Person'</p>
  
  <pre><code>class Airfield &lt; ActiveRecord::Base
    has_many :takeoff_flights, :foreign_key =&gt; "departure_airfield_id", :class_name =&gt; "Flight"
    has_many :grounded_flights, :foreign_key =&gt; "arrival_airfield_id", :class_name =&gt; "Flight"
  end
  
  ###Works Correctly
  
  Airfield.first.takeoff_flights 
  Airfield.first.grounded_flights
  
  Flight.first.departure_airfield
  Flight.first.arrival_airfield
  </code></pre>