Skip to content

Instantly share code, notes, and snippets.

@tarky
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tarky/ce3dd5c0799f9bb6a437 to your computer and use it in GitHub Desktop.
Save tarky/ce3dd5c0799f9bb6a437 to your computer and use it in GitHub Desktop.
destory item without user
models = %w(Theme Entry Vote Activity Feed Follow Notification Authentication)
models.each do | model |
model.constantize.all.each do | obj |
if obj.user.nil?
puts "User #{obj.user_id} doesn't exist. So destroy #{model} #{obj.id}"
obj.destroy
end
end
end
Follow.all.each do | obj |
if obj.user.nil?
puts "Followed #{obj.followed_id} doesn't exist. So destroy Follow #{obj.id}"
obj.destroy
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment