delete events without submitter

This commit is contained in:
Stella Rouzi 2014-07-17 16:48:27 +03:00
parent 79af7266ec
commit b5b85ede71
2 changed files with 17 additions and 1 deletions

View file

@ -0,0 +1,16 @@
class DeleteEventsWithoutUser < ActiveRecord::Migration
def up
# User deletion without all the proper dependent: :destroy options might have left
# Events without a submitter (event_user association is deleted, but Event itslef is not)
Event.all.each do |event|
if event.users.blank?
event.destroy
end
end
end
def down
raise ActiveRecord::IrreversibleMigration, 'Cannot reverse migration. Events deleted cannot be re-created'
end
end