parent
baba6aa9e9
commit
4f503270aa
@ -1,5 +1,5 @@
|
||||
class CourseStageShixun < ApplicationRecord
|
||||
belongs_to :course, counter_cache: :stages_count, counter_cache: :shixuns_count
|
||||
belongs_to :course_stage
|
||||
belongs_to :shixun, counter_cache: :shixuns_count
|
||||
belongs_to :course
|
||||
belongs_to :course_stage, counter_cache: :shixuns_count
|
||||
belongs_to :shixun
|
||||
end
|
||||
|
@ -0,0 +1,14 @@
|
||||
class MigrateCourseStages < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
Course.where(excellent: 1).each do |course|
|
||||
if course.subject
|
||||
course.subject.stages.each do |stage|
|
||||
new_stage = CourseStage.create!(course_id: course.id, name: stage.name, description: stage.description, position: stage.position)
|
||||
stage.stage_shixuns.each do |stage_shixun|
|
||||
CourseStageShixun.create!(course_id: course.id, course_stage_id: new_stage.id, shixun_id: stage_shixun.shixun_id, position: stage_shixun.position)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in new issue