Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Agregar Modelos - second take #2

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions app/models/airport.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# == Schema Information
#
# Table name: airports
#
# id :integer not null, primary key
# code :integer
# location_latitude :float
# location_longitude :float
# name :string
# created_at :datetime not null
# updated_at :datetime not null
#
class Airport < ApplicationRecord
has_many :gates
end
25 changes: 25 additions & 0 deletions app/models/direct_flight.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# == Schema Information
#
# Table name: flights
#
# id :integer not null, primary key
# flight_number :integer
# type :string
# created_at :datetime not null
# updated_at :datetime not null
# indirect_flight_id :integer
# plane_id :integer
#
# Indexes
#
# index_flights_on_indirect_flight_id (indirect_flight_id)
# index_flights_on_plane_id (plane_id)
#
# Foreign Keys
#
# indirect_flight_id (indirect_flight_id => flights.id)
# plane_id (plane_id => planes.id)
#
class DirectFlight < Flight
belongs_to :plane
end
30 changes: 30 additions & 0 deletions app/models/flight.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# == Schema Information
#
# Table name: flights
#
# id :integer not null, primary key
# flight_number :integer
# type :string
# created_at :datetime not null
# updated_at :datetime not null
# indirect_flight_id :integer
# plane_id :integer
#
# Indexes
#
# index_flights_on_indirect_flight_id (indirect_flight_id)
# index_flights_on_plane_id (plane_id)
#
# Foreign Keys
#
# indirect_flight_id (indirect_flight_id => flights.id)
# plane_id (plane_id => planes.id)
#
class Flight < ApplicationRecord
validates :gates, length: { is: 2 }

has_many :direct_flights, class_name: "DirectFlight", foreign_key: "indirect_flight_id"
belongs_to :indirect_flights, class_name: "IndirectFlight", optional: true

has_and_belongs_to_many :gates
end
24 changes: 24 additions & 0 deletions app/models/flight_seat.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# == Schema Information
#
# Table name: seats
#
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
# section_id :integer
# user_id :integer
#
# Indexes
#
# index_seats_on_section_id (section_id)
# index_seats_on_user_id (user_id)
#
# Foreign Keys
#
# section_id (section_id => sections.id)
# user_id (user_id => users.id)
#
class FlightSeat < Seat
validates :section_id, absence: true
belongs_to :user
end
21 changes: 21 additions & 0 deletions app/models/gate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# == Schema Information
#
# Table name: gates
#
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
# airport_id :integer not null
#
# Indexes
#
# index_gates_on_airport_id (airport_id)
#
# Foreign Keys
#
# airport_id (airport_id => airports.id)
#
class Gate < ApplicationRecord
belongs_to :airport
has_and_belongs_to_many :flights
end
26 changes: 26 additions & 0 deletions app/models/indirect_flight.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# == Schema Information
#
# Table name: flights
#
# id :integer not null, primary key
# flight_number :integer
# type :string
# created_at :datetime not null
# updated_at :datetime not null
# indirect_flight_id :integer
# plane_id :integer
#
# Indexes
#
# index_flights_on_indirect_flight_id (indirect_flight_id)
# index_flights_on_plane_id (plane_id)
#
# Foreign Keys
#
# indirect_flight_id (indirect_flight_id => flights.id)
# plane_id (plane_id => planes.id)
#
class IndirectFlight < Flight
validates :direct_flights, length: { minimum: 2 }
validates :indirect_flight_id, absence: true
end
15 changes: 15 additions & 0 deletions app/models/plane.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# == Schema Information
#
# Table name: planes
#
# id :integer not null, primary key
# capacity :integer
# make :string
# name :string
# created_at :datetime not null
# updated_at :datetime not null
#
class Plane < ApplicationRecord
has_many :flights
has_many :sections
end
24 changes: 24 additions & 0 deletions app/models/plane_seat.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# == Schema Information
#
# Table name: seats
#
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
# section_id :integer
# user_id :integer
#
# Indexes
#
# index_seats_on_section_id (section_id)
# index_seats_on_user_id (user_id)
#
# Foreign Keys
#
# section_id (section_id => sections.id)
# user_id (user_id => users.id)
#
class PlaneSeat < Seat
validates :user_id, absence: true
belongs_to :section
end
22 changes: 22 additions & 0 deletions app/models/seat.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# == Schema Information
#
# Table name: seats
#
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
# section_id :integer
# user_id :integer
#
# Indexes
#
# index_seats_on_section_id (section_id)
# index_seats_on_user_id (user_id)
#
# Foreign Keys
#
# section_id (section_id => sections.id)
# user_id (user_id => users.id)
#
class Seat < ApplicationRecord
end
21 changes: 21 additions & 0 deletions app/models/section.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# == Schema Information
#
# Table name: sections
#
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
# plane_id :integer not null
#
# Indexes
#
# index_sections_on_plane_id (plane_id)
#
# Foreign Keys
#
# plane_id (plane_id => planes.id)
#
class Section < ApplicationRecord
belongs_to :plane
has_one :plane_seat
end
19 changes: 19 additions & 0 deletions app/models/section_business.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# == Schema Information
#
# Table name: sections
#
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
# plane_id :integer not null
#
# Indexes
#
# index_sections_on_plane_id (plane_id)
#
# Foreign Keys
#
# plane_id (plane_id => planes.id)
#
class SectionBusiness < Section
end
19 changes: 19 additions & 0 deletions app/models/section_economy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# == Schema Information
#
# Table name: sections
#
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
# plane_id :integer not null
#
# Indexes
#
# index_sections_on_plane_id (plane_id)
#
# Foreign Keys
#
# plane_id (plane_id => planes.id)
#
class SectionEconomy < Section
end
16 changes: 16 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# name :string
# nationality :string
# passaport :string
# phone :integer
# string :string
# created_at :datetime not null
# updated_at :datetime not null
#
class User < ApplicationRecord
has_one :flight_seat
end
12 changes: 12 additions & 0 deletions db/migrate/20240708112238_create_airports.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateAirports < ActiveRecord::Migration[7.1]
def change
create_table :airports do |t|
t.integer :code
t.float :location_latitude
t.float :location_longitude
t.string :name

t.timestamps
end
end
end
9 changes: 9 additions & 0 deletions db/migrate/20240708112247_create_gates.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateGates < ActiveRecord::Migration[7.1]
def change
create_table :gates do |t|
t.references :airport, null: false, foreign_key: true

t.timestamps
end
end
end
11 changes: 11 additions & 0 deletions db/migrate/20240708113148_create_flights.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateFlights < ActiveRecord::Migration[7.1]
def change
create_table :flights do |t|
t.integer :flight_number
t.string :type
t.references :indirect_flight, foreign_key: { to_table: :flights }

t.timestamps
end
end
end
5 changes: 5 additions & 0 deletions db/migrate/20240708121650_relate_gate_and_flight.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RelateGateAndFlight < ActiveRecord::Migration[7.1]
def change
create_join_table :flights, :gates
end
end
11 changes: 11 additions & 0 deletions db/migrate/20240708123754_create_planes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreatePlanes < ActiveRecord::Migration[7.1]
def change
create_table :planes do |t|
t.integer :capacity
t.string :make
t.string :name

t.timestamps
end
end
end
5 changes: 5 additions & 0 deletions db/migrate/20240708123815_flight_references_plane.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class FlightReferencesPlane < ActiveRecord::Migration[7.1]
def change
add_reference :flights, :plane, foreign_key: true
end
end
9 changes: 9 additions & 0 deletions db/migrate/20240708125100_create_sections.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateSections < ActiveRecord::Migration[7.1]
def change
create_table :sections do |t|
t.references :plane, null: false, foreign_key: true

t.timestamps
end
end
end
13 changes: 13 additions & 0 deletions db/migrate/20240708134956_create_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateUsers < ActiveRecord::Migration[7.1]
def change
create_table :users do |t|
t.string :name
t.string :nationality
t.string :passaport
t.string :string
t.integer :phone

t.timestamps
end
end
end
10 changes: 10 additions & 0 deletions db/migrate/20240708135025_create_seats.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateSeats < ActiveRecord::Migration[7.1]
def change
create_table :seats do |t|
t.references :user, foreign_key: true
t.references :section, foreign_key: true

t.timestamps
end
end
end
Loading