title: Rails Includes not returning all child records
body: <p>I have the following query which grabs <code>Orders</code> that have <code>Addresses</code> where the state is <code>Texas</code>.</p>
  
  <pre><code>orders = Order.includes(:addresses).where(:addresses =&gt; {state: "Texas"})
  </code></pre>
  
  <p>I am able to get all of my orders, but I noticed while accessing the addresses that not all of the addresses were stored in memory. </p>
  
  <p>Here is how I found the issue:</p>
  
  <pre><code>orders.each do |i|
      puts orders.addresses.length #outputs 1 or 2 randomly
      puts orders.addresses.count #outputs 2 every time
  end
  </code></pre>
  
  <p>All of my orders have two addresses; one billing and one shipping. Printing <code>length</code> would show only <code>1</code> for about half the records and would show <code>2</code> for the other half. Printing <code>count</code> always showed <code>2</code>. If I changed the query from includes to joins, it worked correctly but would not "include" addresses in the query. </p>
  
  <p>UPDATE </p>
  
  <p>Changing <code>includes</code> to <code>joins</code> in the query above causes everything to work as expected. However, I lose the preloading. I don't understand why includes is not working here. Something seems wrong. </p>