ruby on rails 4 - ActiveRecord Query to identify orphan child records -


i have post , user models. every post belongs user. however, during database import, erroneous user_ids have been entered on posts. query posts user_ids don't refer user? thanks.

i following, result in 1 select , 1 delete statement

post.where('`posts`.`user_id` not in (?)', user.pluck(:id)).delete_all 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -