title: includes called on a relation in AR. Does it scope on the relation or the entire database?
body: <p>I have an odd situation where an has_many association yields me an empty collection but a scope on an empty collection yields me a record. Any idea what is going on?</p>
  
  <pre><code>class Person
    has_many :apples
  
  end
  
  Class Apple
    belongs_to :person
  
    scope :rotten, -&gt; { includes(pit: :seed).where(seeds: { seed_type_id: Seedtype.edible.id})
  end
  </code></pre>
  
  <p>Inside the Person model:</p>
  
  <pre><code>=&gt; Apple.all
  [
      [0] #&lt;Apple:0x007fdff8b49b70&gt; {
                             :id =&gt; 1,
                        :user_id =&gt; 1,
      }
  ]
  
  =&gt; apples
  []
  
  =&gt; apples.rotten
  [
      [0] #&lt;Apple:0x007fdff8b49b70&gt; {
                             :id =&gt; 1,
                        :user_id =&gt; 1
      }
  ]
  </code></pre>
  
  <p>Any ideas as to what is going on?</p>
  
  <p>My guess is that when I call apple.includes... the includes is not actually being called on the empty collection but the class. Is that right?</p>