class AddDataToStudentForCourseNew < ActiveRecord::Migration
  def change
    Course.all.each do |course|

      course.members.each do |m|
        if m && m.user && m.user.allowed_to?(:as_student,course) &&
            StudentsForCourse.where(:student_id => m.user_id, :course_id => course.id).first.nil?
          student = StudentsForCourse.new(:student_id => m.user_id, :course_id => course.id)
          student.save!
        end

      end
    end
  end
end
