迁移空数据问题
This commit is contained in:
parent
081aea8b02
commit
5d506458df
|
@ -1,16 +1,20 @@
|
|||
class DeleteAnonymousWork < ActiveRecord::Migration
|
||||
def up
|
||||
student_works = StudentWork.where("homework_common_id = 2882").map{|work| work.id} unless StudentWork.where("homework_common_id = 2882").empty?
|
||||
student_work_ids = "(" + student_works.join(",") + ")"
|
||||
student_work_scores = StudentWorksScore.where("student_work_id in #{student_work_ids}")
|
||||
unless student_work_scores.empty?
|
||||
student_work_scores.each do |sscore|
|
||||
student_work = StudentWork.find sscore.student_work_id
|
||||
student_work.student_score = 0 unless student_work.nil?
|
||||
student_work.absence_penalty = 0
|
||||
sscore.destroy
|
||||
student_work.save
|
||||
begin
|
||||
student_works = StudentWork.where("homework_common_id = 2882").map{|work| work.id} unless StudentWork.where("homework_common_id = 2882").empty?
|
||||
student_work_ids = "(" + student_works.join(",") + ")"
|
||||
student_work_scores = StudentWorksScore.where("student_work_id in #{student_work_ids}")
|
||||
unless student_work_scores.empty?
|
||||
student_work_scores.each do |sscore|
|
||||
student_work = StudentWork.find sscore.student_work_id
|
||||
student_work.student_score = 0 unless student_work.nil?
|
||||
student_work.absence_penalty = 0
|
||||
sscore.destroy
|
||||
student_work.save
|
||||
end
|
||||
end
|
||||
rescue => e
|
||||
logger.error "[Errno::ENOENT] ===> #{e}"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue