Skip to content
This repository was archived by the owner on Mar 28, 2024. It is now read-only.

Commit 7c2699c

Browse files
committed
Add core model relationships
1 parent 87134f9 commit 7c2699c

6 files changed

Lines changed: 35 additions & 0 deletions

File tree

app/models/email_address.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313
# fk_rails_... (teacher_id => teachers.id)
1414
#
1515
class EmailAddress < ApplicationRecord
16+
belongs_to :teacher
1617
end

app/models/induction_period.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@
1818
# fk_rails_... (mentorship_id => mentorships.id)
1919
#
2020
class InductionPeriod < ApplicationRecord
21+
belongs_to :mentorship
22+
belongs_to :appropriate_body
23+
belongs_to :induction_programme
2124
end

app/models/mentorship.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,9 @@
1414
# fk_rails_... (tenureship_id => tenureships.id)
1515
#
1616
class Mentorship < ApplicationRecord
17+
belongs_to :tenureship
18+
belongs_to :mentor, class_name: 'Teacher', foreign_key: 'teacher_id'
19+
has_one :mentee, through: :tenureship, source: :teacher
20+
has_many :induction_periods
21+
has_many :induction_programmes, through: :induction_periods
1722
end

app/models/school.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,19 @@
1313
# fk_rails_... (parent_id => schools.id)
1414
#
1515
class School < ApplicationRecord
16+
# naming could be better here, avoiding parent/children for obvious reasons
17+
belongs_to :mat, class_name: 'School', foreign_key: 'parent_id', optional: true
18+
has_many :schools, class_name: 'School', foreign_key: 'parent_id'
19+
has_many :tenureships
20+
has_many :teachers, through: :tenureships, source: :teacher
21+
22+
has_many :mentorships_as_mentee,
23+
through: :tenureships,
24+
source: :mentorships,
25+
class_name: 'Mentorship'
26+
27+
has_many :mentorships_as_mentor,
28+
through: :teachers,
29+
source: :mentorships_as_mentor,
30+
class_name: 'Mentorship'
1631
end

app/models/teacher.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,12 @@
99
# updated_at :datetime not null
1010
#
1111
class Teacher < ApplicationRecord
12+
has_many :email_addresses
13+
has_many :tenureships
14+
15+
has_many :mentorships_as_mentor, class_name: 'Mentorship', foreign_key: 'teacher_id'
16+
has_many :mentorships_as_mentee, class_name: 'Mentorship', through: :tenureships, source: :mentorships
17+
18+
has_many :mentors, through: :mentorships_as_mentee, source: :mentor
19+
has_many :mentees, through: :mentorships_as_mentor, source: :mentee
1220
end

app/models/tenureship.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@
1616
# fk_rails_... (teacher_id => teachers.id)
1717
#
1818
class Tenureship < ApplicationRecord
19+
belongs_to :teacher
20+
belongs_to :school
21+
has_many :mentorships
1922
end

0 commit comments

Comments
 (0)