Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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