socialforge/db/migrate/20170217104309_delete_exces...

24 lines
676 B
Ruby
Raw Normal View History

2017-02-17 18:54:15 +08:00
class DeleteExcessStudentWorks < ActiveRecord::Migration
def up
homework = HomeworkCommon.where(:id => 4818)
unless homework.empty?
homework = homework.first
homework.course.student.each do |student|
student_works = homework.student_works.where(:user_id => student.student_id).reorder("created_at asc")
if student_works.count > 1
if student_works.first.work_status != 0
student_works.last.destroy
elsif student_works.last.work_status != 0
student_works.first.destroy
else
student_works.first.destroy
end
end
end
end
end
def down
end
end