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.
30 lines
1.0 KiB
30 lines
1.0 KiB
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") #试卷的位置迁移
|
|
if ex_questions.present?
|
|
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)
|
|
end
|
|
end
|
|
end
|
|
|
|
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.present?
|
|
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)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
end
|
|
end
|