YannisRoss / flight-booker

A Rails website for booking flights
0 stars 0 forks source link

flesh out data architecture #1

Closed YannisRoss closed 3 years ago

YannisRoss commented 3 years ago

A typical airline booking flow:

Enter desired dates / airports and click “Search”
Choose from among a list of eligible flights
Enter passenger information for all passengers
Enter billing information

As per TheOdinProject:

This project will require you to seed your database, 
so use your db/seeds.rb file to write the code necessary
to populate Airports and Flights. 

One trick for toy apps like this (don’t do it for production!) is to make your seeds file 
::delete_all items from each table in your database and then 
completely repopulate them. 

That way, when you create a new 
model or change how you want your sample data set up, 
you can just update the seeds.rb file and rerun $ rake db:seed.
YannisRoss commented 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"
YannisRoss commented 3 years ago

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