Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save barangerbenjamin/1f1e0270c23c0fe83828f202d74d481f to your computer and use it in GitHub Desktop.
Save barangerbenjamin/1f1e0270c23c0fe83828f202d74d481f to your computer and use it in GitHub Desktop.
class CreateDoctors < ActiveRecord::Migration[5.1]
def change
create_table :doctors do |t|
t.string :first_name
t.string :last_name
t.timestamps
end
end
end
class CreateInterns < ActiveRecord::Migration[5.1]
def change
create_table :interns do |t|
t.string :first_name
t.string :last_name
t.references :doctor, index: true
t.timestamps
end
end
end
class CreatePatients < ActiveRecord::Migration[5.1]
def change
create_table :patients do |t|
t.string :first_name
t.string :last_name
t.timestamps
end
end
end
class CreateConsultations < ActiveRecord::Migration[5.1]
def change
create_table :consultations do |t|
t.references :doctor, index: true
t.references :patient, index: true
t.timestamps
end
end
end
class Consultation < ActiveRecord::Base
belongs_to :patient
belongs_to :doctor
end
class Doctor < ActiveRecord::Base
has_many :interns
has_many :consultations
has_many :patients, through: :consultations
validates :last_name, presence: true
end
class Intern < ActiveRecord::Base
belongs_to :doctor
end
class Patient < ActiveRecord::Base
has_many :consultations
has_many :doctors, through: :consultations
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment