28 lines
802 B
Ruby
28 lines
802 B
Ruby
class ChangeSeemsRateableRates < ActiveRecord::Migration
|
|
def up
|
|
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
|
|
|
|
def down
|
|
SeemsRateableRates.where("is_teacher_score = 1").each do |rate|
|
|
rate.is_teacher_score = 0
|
|
rate.save
|
|
end
|
|
end
|
|
end
|