title: Find user who has no post in Rails
body: <p>This the the database relation:</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    has_many :posts
  end
  
  class Post &lt; ActiveRecord::Base
    belongs_to :user
  end
  </code></pre>
  
  <p>I come across a functionality where I want to query all the users who don't have any posts yet. I know that we can do this with something like this:</p>
  
  <pre><code>users = User.all
  users.each do |user|
    unless user.posts.any?
      # do something when user don't have any post.
    end
  end
  </code></pre>
  
  <p>However, I wonder if there is any way to optimize this by using one query only.</p>
  
  <p>Thanks!</p>