delete events without submitter
This commit is contained in:
parent
7ebfbae7ab
commit
d36fcd9894
1 changed files with 16 additions and 0 deletions
16
db/migrate/20140717110124_delete_events_without_user.rb
Normal file
16
db/migrate/20140717110124_delete_events_without_user.rb
Normal 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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue