diff --git a/app/models/competition.rb b/app/models/competition.rb index 9adf6af17..cfcc1c4dc 100644 --- a/app/models/competition.rb +++ b/app/models/competition.rb @@ -185,7 +185,6 @@ class Competition < ApplicationRecord def set_laboratory return unless new_record? - return if Laboratory.current.blank? || Laboratory.current.main_site? self.laboratory = Laboratory.current end diff --git a/app/models/course.rb b/app/models/course.rb index 80be1d895..394d14f47 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -415,7 +415,6 @@ class Course < ApplicationRecord def set_laboratory return unless new_record? # 新记录才需要标记 - return if Laboratory.current.blank? || Laboratory.current.main_site? self.laboratory = Laboratory.current end diff --git a/app/models/laboratory.rb b/app/models/laboratory.rb index afee81efc..792f8620e 100644 --- a/app/models/laboratory.rb +++ b/app/models/laboratory.rb @@ -11,6 +11,9 @@ class Laboratory < ApplicationRecord has_many :laboratory_shixuns, dependent: :destroy has_many :laboratory_subjects, dependent: :destroy + has_many :courses, dependent: :destroy + has_many :competitions, dependent: :destroy + validates :identifier, uniqueness: { case_sensitive: false }, allow_nil: true delegate :name, :navbar, :footer, :login_logo_url, :nav_logo_url, :tab_logo_url, :default_navbar, to: :laboratory_setting @@ -47,14 +50,6 @@ class Laboratory < ApplicationRecord main_site? ? Subject.all : Subject.joins(:laboratory_subjects).where(laboratory_subjects: { laboratory_id: id }) end - def courses - main_site? ? Course.all : Course.where(laboratory_id: self.id) - end - - def competitions - main_site? ? Competition.all : Competition.where(laboratory_id: self.id) - end - def shixun_repertoires where_sql = ShixunTagRepertoire.where("shixun_tag_repertoires.tag_repertoire_id = tag_repertoires.id")