title: Rails: Query parents with grandchildren (associations)
body: <pre><code>class User &lt; ActiveRecord::Base
    has_many :posts
  end
  
  class Question &lt; ActiveRecord::Base
    belongs_to :user
    has_many :answers
  end
  
  class Answer &lt; ActiveRecord::Base
    belongs_to :question
  end
  </code></pre>
  
  <p><strong>Using Rails how can I:</strong> </p>
  
  <p>1.Return all <code>users</code> with <code>questions</code>? eg.</p>
  
  <pre><code>@users_with_questions = User.joins(:question).where.not(question: { id: nil })
  </code></pre>
  
  <p>2.Return all <code>users</code> with <code>answers</code>?</p>