You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

28 lines
793 B

class Cdao::LibrarySubject < Cdao::Base
acts_as_list column: :rank, scope: %i[library_id subject_parent_id]
belongs_to :library, optional: false
delegate :name, :rank, to: :library, prefix: true
belongs_to :subject, optional: false
validates :library_id, uniqueness: { scope: %i[subject_id] }
after_save do
update_column :subject_parent_id, subject.parent_id # rubocop:disable Rails/SkipsModelValidations
end
def self.import
Subject.find_each do |subject|
subject.library_subjects.where(library_id: subject.library_id).first_or_create
end
end
def self.import_rank_from_subjects
Subject.find_each do |subject|
subject.library_subjects.each do |subject_library|
subject_library.update(rank: subject.rank)
end
end
end
end