班级删除成员后,隐藏对应作品记录历史数据迁移
This commit is contained in:
parent
6a6dda2ec3
commit
8efcf876c6
|
@ -0,0 +1,18 @@
|
|||
class MigrateStudentWorks < ActiveRecord::Migration
|
||||
def up
|
||||
count = Course.all.count / 30 + 2
|
||||
transaction do
|
||||
for i in 1 ... count do i
|
||||
Course.page(i).per(30).each do |course|
|
||||
homework_ids = course.homework_commons.blank? ? "(-1)" : "(" + course.homework_commons.map{|hw| hw.id}.join(",") + ")"
|
||||
student_ids = course.student.blank? ? "(-1)" : "(" + course.student.map{|st| st.student_id}.join(",") + ")"
|
||||
student_works = StudentWork.where("homework_common_id in #{homework_ids} and user_id not in #{student_ids}")
|
||||
student_works.update_all(:is_delete => 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue