I do not know if there is a direct path. But you can write a script that handles this. Say your model looks like this.
class Post
belongs_to: user
end
Here you can use a script like this
Post.all.each do | post |
post.delete if post.user.nil?
end
Its simpler and harder than writing SQL. But this time, take a database dump before trying to do the magic
source
share