From e2c0237fcd8b75358242b1247806cb05a406bf62 Mon Sep 17 00:00:00 2001 From: huang Date: Tue, 30 Aug 2016 15:30:01 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E7=A9=BA=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20160511055221_merge_two_homeworks.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/db/migrate/20160511055221_merge_two_homeworks.rb b/db/migrate/20160511055221_merge_two_homeworks.rb index a30bc983b..42aabbbd9 100644 --- a/db/migrate/20160511055221_merge_two_homeworks.rb +++ b/db/migrate/20160511055221_merge_two_homeworks.rb @@ -6,13 +6,17 @@ class MergeTwoHomeworks < ActiveRecord::Migration work.update_column('homework_common_id', 3463) end end - homework = HomeworkCommon.find 3387 - homework.destroy if homework - stu_works = StudentWork.where("homework_common_id = 3387") - stu_work_ids = stu_works.empty? ? "(-1)" : "(" + stu_works.map{|work| work.id}.join(',') + ")" - stu_work_tests = StudentWorkTest.where("student_work_id in #{stu_work_ids}") - stu_work_tests.destroy_all if stu_work_tests - stu_works.destroy_all if stu_works + begin + homework = HomeworkCommon.find 3387 + homework.destroy if homework + stu_works = StudentWork.where("homework_common_id = 3387") + stu_work_ids = stu_works.empty? ? "(-1)" : "(" + stu_works.map{|work| work.id}.join(',') + ")" + stu_work_tests = StudentWorkTest.where("student_work_id in #{stu_work_ids}") + stu_work_tests.destroy_all if stu_work_tests + stu_works.destroy_all if stu_works + rescue Exception => e + puts e + end end def down