So I have a Post and a User. Post has_many users and a user belongs_to a post. I need a find that will find all the Posts that dont have any users like the following:
Learned this one just today:
Post.eager_load(:users).merge(User.where(id: nil))
Works with Rails 4+ at least.
Update:
In Rails 5+, you can use left_joins instead:
left_joins
Post.left_joins(:users).merge(User.where(id: nil))