0

Есть две модели, Airport и Flight

У Flight может быть аэропорт вылета и аэропорт прилета

belongs_to :origin, class_name: 'Airport', foreign_key: :origin_id
belongs_to :destination, class_name: 'Airport', foreign_key: :destination_id

Airport может быть у многих рейсов как аэропортом вылета, так и аэропортом прилета

has_many :flights, foreign_key: :destination_id
has_many :flights, foreign_key: :origin_id

1 ответ 1

2

Ассоциация в Airport должна быть такой:

has_many :destination_flights, foreign_key: :destination_id, class_name: 'Flight'
has_many :origin_flights, foreign_key: :origin_id, class_name: 'Flight'
0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.