From 0a58fce2515cf0e1f10efcd7d7c03c1bd2295a8a Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Mon, 29 Dec 2014 11:53:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=95=B0=E6=8D=AE=E8=BF=81?= =?UTF-8?q?=E7=A7=BB=E6=95=88=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...41229025925_change_seems_rateable_rates.rb | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/db/migrate/20141229025925_change_seems_rateable_rates.rb b/db/migrate/20141229025925_change_seems_rateable_rates.rb index 9ea75e68e..7be2a81fe 100644 --- a/db/migrate/20141229025925_change_seems_rateable_rates.rb +++ b/db/migrate/20141229025925_change_seems_rateable_rates.rb @@ -1,23 +1,27 @@ class ChangeSeemsRateableRates < ActiveRecord::Migration def up - SeemsRateableRates.where("rateable_type = 'HomeworkAttach'").each do |rate| - homework = HomeworkAttach.find_by_id rate.rateable_id - if homework - course = homework.bid.courses.first - if course - teachers = [] - course.members.each do |m| - teachers << m.user_id if m && m.user && m.user.allowed_to?(:as_teacher,course) - end - if teachers.include?(rate.rater_id) - rate.is_teacher_score = 1 - rate.save + Course.all.each do |course| + teachers = [] + course.members.each do |m| + teachers << m.user_id if m && m.user && m.user.allowed_to?(:as_teacher,course) + end + course.homeworks.each do |bid| + bid.homeworks.each do |homework| + SeemsRateableRates.where("rateable_type = 'HomeworkAttach' and rateable_id = #{homework.id}").each do |rate| + if teachers.include?(rate.rater_id) + rate.is_teacher_score = 1 + rate.save + end + end end end end - end end def down + SeemsRateableRates.where("is_teacher_score = 1").each do |rate| + rate.is_teacher_score = 0 + rate.save + end end end