Two belong_to to same model

I have a reservation class which has origin_city and destination_city,
both of which are instance of location class. How would I represent
this using belongs_to relationship. I would like something like:
class Location …
has_one reservation for origin_city
has_one reservation for destination_city

class Reservaton
belongs_to :location, :as => origin_city
belongs_to :location, :as => destination_city

Can someone correct the exact syntax for me.

On 21 Nov 2007, at 15:43, sabrinih wrote:

belongs_to :location, :as => destination_city

That’s not quite right.

On Reservation you want

belongs_to :origin_city, :class_name => ‘Location’, :foreign_key =>
and similarly for the other one
on Location you probably want

has_many :origin_reservations, :class_name =>
‘Reservation’, :foreign_key => origin_city_id’

I’m assuming you want has_many instead of has_one unless it’s the case
that a location can only be used be a single reservation