Two Foreign Keys between Same Tables : How To Display Data

My model is -

class TripLeg < ActiveRecord::Base   belongs_to :airport, :foreign_key => :start_airport_id   belongs_to :airport, :foreign_key => :end_airport_id   belongs_to :trip   has_many :trip_leg_passengers validates_presence_of :trip_id, :trip_id_sequence, :start_airport_id, :end_airport_id end

You'll notice the two foreign keys to airport, for the start and end point of the trip leg.

I now want to display the airport names on a view. I'd normally code -


but this doesn't work here.

How do I tell it to go from a specific column to airport ?



Worked it out with help from IRC

Changed to -

belongs_to :start_airport, :class_name => 'Airport', :foreign_key => :start_airport_id belongs_to :end_airport , :class_name => 'Airport', :foreign_key => :end_airport_id

and then I code -

trip_leg.start_airport.airport_city trip_leg.end_airport.airport_city