Closed YannisRoss closed 3 years ago
Airport
has_many :outbound_flights, foreign_key: "flight_id"
has_many :inbound_flights, foreign_key: "flight_id"
Flight
belongs_to :departure_airport, foreign_key: "airport_id"
belongs_to :destination_airport, foreign_key: "airport_id"
Flight - Booking - Passenger models
class Flight < ApplicationRecord
has_many :passengers, through: :bookings
has_many :bookings
class Passenger < ApplicationRecord
has_many :flights, through: :bookings
has_many :bookings
class Booking < ApplicationRecord
belongs_to :flight
belongs_to :passenger
A typical airline booking flow:
As per TheOdinProject: