ensure that deleted courses also delete enrollments

closes #3833

Change-Id: I21efa68116b7a250e9b0e9c2df2dd5dfd45a736e
Reviewed-on: https://gerrit.instructure.com/2301
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Brian Whitmer <brian@instructure.com>
This commit is contained in:
Bracken Mosbacker 2011-02-15 16:08:51 -07:00
parent f9d40283da
commit e1a3350d7e
1 changed files with 3 additions and 0 deletions

View File

@ -437,6 +437,9 @@ class Course < ActiveRecord::Base
if self.completed?
enrollments = self.enrollments.scoped(:select => "id, user_id, course_id", :conditions=>"workflow_state IN ('active', 'invited')")
Enrollment.update_all({:workflow_state => 'completed'}, {:id => enrollments.map(&:id)})
elsif self.deleted?
enrollments = self.enrollments.scoped(:select => "id, user_id, course_id", :conditions=>"workflow_state != 'deleted'")
Enrollment.update_all({:workflow_state => 'deleted'}, {:id => enrollments.map(&:id)})
end
enrollments = self.enrollments.scoped(:select => "id, user_id, course_id")
Enrollment.update_all({:updated_at => Time.now}, {:id => enrollments.map(&:id)})