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.
educoder/db/migrate/20190703072611_add_old_exer...

24 lines
1.4 KiB

class AddOldExerciseTiankongChoiceId < ActiveRecord::Migration[5.2]
def up
#类型为3 的问题答案及标准答案更新exercise_choice_id 为1即表示第一空
exercise_question_ids = ExerciseQuestion.where("question_type = 3").pluck(:id)
ExerciseAnswer.where(exercise_question_id: exercise_question_ids,exercise_choice_id: nil).update_all(exercise_choice_id:1)
ExerciseStandardAnswer.where(exercise_question_id: exercise_question_ids,exercise_choice_id: nil).update_all(exercise_choice_id:1)
exercise_bank_question_ids = ExerciseBankQuestion.where("question_type =3").pluck(:id)
ExerciseBankStandardAnswer.where(exercise_bank_question_id: exercise_bank_question_ids).update_all(exercise_bank_choice_id:1)
end
def down
#类型为3 的问题答案及标准答案更新exercise_choice_id 为1即表示第一空
exercise_question_ids = ExerciseQuestion.where("question_type = 3").pluck(:id)
ExerciseAnswer.where(exercise_question_id: exercise_question_ids,exercise_choice_id: 1).update_all(exercise_choice_id:nil)
ExerciseStandardAnswer.where(exercise_question_id: exercise_question_ids,exercise_choice_id: 1).update_all(exercise_choice_id:nil)
exercise_bank_question_ids = ExerciseBankQuestion.where("question_type =3").pluck(:id)
ExerciseBankStandardAnswer.where(exercise_bank_question_id: exercise_bank_question_ids).update_all(exercise_bank_choice_id:nil)
end
end