title: Using Rails includes with conditions on children
body: <p>I have a model <code>Parent</code> that has many children <code>Child</code>.  I want to get all Parent models and show every <code>Child</code> of the Parent as well.  This is a classic use case for Rails' <code>includes</code> method, as far as I can tell.</p>
  
  <p>However, I can't get Rails to add conditions to the child models without limiting the Parent models to those that have children.</p>
  
  <p>For example, this only outputs parents that have children:</p>
  
  <pre><code>Parent.includes(:children).where(children: {age: 10}).each do |parent|
    # output parent info
    parent.children.where("age = 10").each do |child|
     #output child info
    end
  end
  </code></pre>
  
  <p>I've looked at <a href="https://stackoverflow.com/questions/16348333/rails-includes-with-conditions">Rails includes with conditions</a> but it seems like I'm having the same trouble as the question's OP and neither part of the accepted answer doesn't solve it (it either has only some parents, or resorts to multiple queries).</p>