Skip to content

Commit

Permalink
Make flights dependent on airports
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenjessev committed Jun 18, 2021
1 parent cc48d3a commit 92db4cf
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/models/airport.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Airport < ApplicationRecord
has_many :departing_flights, foreign_key: 'from_airport_id', class_name: 'Flight'
has_many :arriving_flights, foreign_key: 'to_airport_id', class_name: 'Flight'
has_many :departing_flights, foreign_key: 'from_airport_id', class_name: 'Flight', dependent: :destroy
has_many :arriving_flights, foreign_key: 'to_airport_id', class_name: 'Flight', dependent: :destroy
end
2 changes: 1 addition & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)

Flight.destroy_all
Airport.destroy_all

Airport.create(code: 'ATL')
Expand All @@ -15,6 +14,7 @@
Airport.create(code: 'ORD')
Airport.create(code: 'LAX')

Flight.destroy_all
Flight.create(from_airport_id: Airport.first.id, to_airport_id: Airport.second.id, start: '2021-12-12 08:30:00.000', duration_in_mins: 150)
Flight.create(from_airport_id: Airport.first.id, to_airport_id: Airport.third.id, start: '2021-12-10 07:30:00.000', duration_in_mins: 180)
Flight.create(from_airport_id: Airport.second.id, to_airport_id: Airport.fourth.id, start: '2021-12-10 07:30:00.000', duration_in_mins: 140)
Expand Down

0 comments on commit 92db4cf

Please sign in to comment.