|
|
|
@ -2,9 +2,10 @@ class ChangeExercise1930Position < ActiveRecord::Migration[5.2]
|
|
|
|
|
def change
|
|
|
|
|
exs = Exercise.all.includes(:exercise_questions)
|
|
|
|
|
exs.each do |ex|
|
|
|
|
|
ex_questions = ex&.exercise_questions&.select(:id,:question_number,:exercise_id)&.order("question_number ASC")
|
|
|
|
|
ex_questions = ex&.exercise_questions&.select(:id,:question_number,:exercise_id)&.order("question_number ASC") #试卷的位置迁移
|
|
|
|
|
if ex_questions.exists?
|
|
|
|
|
ex_questions.each_with_index do |q,index|
|
|
|
|
|
puts index
|
|
|
|
|
q_num = index + 1
|
|
|
|
|
if q.question_number.to_i != q_num
|
|
|
|
|
q.update_attributes(question_number: q_num)
|
|
|
|
@ -12,9 +13,10 @@ class ChangeExercise1930Position < ActiveRecord::Migration[5.2]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
ex_q_bank = ex&.exercise_bank&.exercise_bank_questions&.select(:id,:question_number,:exercise_bank_id,:shixun_id)&.order("question_number ASC")
|
|
|
|
|
ex_q_bank = ex&.exercise_bank&.exercise_bank_questions&.select(:id,:question_number,:exercise_bank_id,:shixun_id)&.order("question_number ASC") #试卷的习题库位置迁移
|
|
|
|
|
if ex_q_bank.exists?
|
|
|
|
|
ex_q_bank.each_with_index do |q,index|
|
|
|
|
|
puts index
|
|
|
|
|
q_num_1 = index + 1
|
|
|
|
|
if q.question_number.to_i != q_num_1
|
|
|
|
|
q.update_attributes(question_number: q_num_1)
|
|
|
|
|