Skip to content

Commit

Permalink
fix existing inverse_of associations
Browse files Browse the repository at this point in the history
  • Loading branch information
fosterfarrell9 committed Dec 8, 2023
1 parent c3abe9f commit 2a730ff
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/models/lecture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Lecture < ApplicationRecord
# rubocop:todo Rails/HasManyOrHasOneDependent
has_many :media, -> { order(position: :asc) },
as: :teachable,
inverse_of: :lecture
inverse_of: :teachable
# rubocop:enable Rails/HasManyOrHasOneDependent

# in a lecture, you can import other media
Expand Down
2 changes: 1 addition & 1 deletion app/models/lesson.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Lesson < ApplicationRecord
# being a teachable (course/lecture/lesson), a lesson has associated media
has_many :media, -> { order(position: :asc) }, # rubocop:todo Rails/HasManyOrHasOneDependent
as: :teachable,
inverse_of: :lesson
inverse_of: :teachable

validates :date, presence: true
validates :sections, presence: true
Expand Down
2 changes: 1 addition & 1 deletion app/models/medium.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Medium < ApplicationRecord

has_many :quiz_certificates, foreign_key: "quiz_id",
dependent: :destroy,
inverse_of: :medium
inverse_of: :quiz

# a medium can be in watchlists of multiple users
has_many :watchlist_entries, dependent: :destroy
Expand Down
2 changes: 1 addition & 1 deletion app/models/speaker_talk_join.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class SpeakerTalkJoin < ApplicationRecord
belongs_to :talk
belongs_to :speaker, class_name: "User", inverse_of: :speaker_talk_join
belongs_to :speaker, class_name: "User", inverse_of: :speaker_talk_joins
end
2 changes: 1 addition & 1 deletion app/models/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Tag < ApplicationRecord
has_many :aliases, # rubocop:todo Rails/HasManyOrHasOneDependent
foreign_key: "aliased_tag_id",
class_name: "Notion",
inverse_of: :tag
inverse_of: :aliased_tag

serialize :realizations, Array

Expand Down
2 changes: 1 addition & 1 deletion app/models/talk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Talk < ApplicationRecord
# being a teachable (course/lecture/lesson), a talk has associated media
has_many :media, -> { order(position: :asc) }, as: :teachable,
dependent: :destroy,
inverse_of: :talk
inverse_of: :teachable

# a talk has many tags
has_many :talk_tag_joins, dependent: :destroy
Expand Down
2 changes: 1 addition & 1 deletion app/models/tutor_tutorial_join.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class TutorTutorialJoin < ApplicationRecord
belongs_to :tutorial
belongs_to :tutor, class_name: "User", inverse_of: :tutor_tutorial_join
belongs_to :tutor, class_name: "User", inverse_of: :tutor_tutorial_joins
end
12 changes: 6 additions & 6 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,41 +34,41 @@ class User < ApplicationRecord
has_many :given_lectures,
class_name: "Lecture",
foreign_key: "teacher_id",
inverse_of: :user
inverse_of: :teacher
# rubocop:enable Rails/HasManyOrHasOneDependent

# a user has many tutorials as a tutor

has_many :tutor_tutorial_joins,
foreign_key: "tutor_id",
dependent: :destroy,
inverse_of: :user
inverse_of: :tutor
has_many :given_tutorials, -> { order(:title) },
through: :tutor_tutorial_joins, source: :tutorial

# a user has many given talks
has_many :speaker_talk_joins,
foreign_key: "speaker_id",
dependent: :destroy,
inverse_of: :user
inverse_of: :speaker
has_many :talks, through: :speaker_talk_joins

# a user has many notifications as recipient
has_many :notifications, # rubocop:todo Rails/HasManyOrHasOneDependent
foreign_key: "recipient_id",
inverse_of: :user
inverse_of: :recipient

# a user has many announcements as announcer
has_many :announcements,
foreign_key: "announcer_id",
dependent: :destroy,
inverse_of: :user
inverse_of: :announcer

# a user has many clickers as editor
has_many :clickers,
foreign_key: "editor_id",
dependent: :destroy,
inverse_of: :user
inverse_of: :editor

# a user has many submissions (of assignments)
has_many :user_submission_joins, dependent: :destroy
Expand Down

0 comments on commit 2a730ff

Please sign in to comment.