title: Using includes with multiple associations and separate conditions
body: <p>I have the following query in my <code>Gallery</code> model:</p>
  
  <pre><code>media_items.includes(:photo, :video).rank(:position_in_gallery)
  </code></pre>
  
  <p>My <code>Gallery</code> Model has_many <code>Media Items</code> which each have either a <code>Photo</code> or <code>Video</code> association.</p>
  
  <p>So far this works fine. It returns all the <code>media_items</code> including their
  <code>photo</code> or <code>video</code> association, ordered by the <code>position_in_gallery</code> attribute of the <code>media_item</code>. </p>
  
  <p>However I now have a requirement to limit the Photos returned by this query to only those with an attribute of <code>is_processing</code> that is <code>nil</code>.</p>
  
  <p>Is it possible to make this same query but with a condition on the photos returned equivalent to:</p>
  
  <pre><code>.where(photo: 'photo.is_processing IS NULL')
  </code></pre>
  
  <p>Note that all the videos should be returned regardless and do not include an <code>is_processing</code> attribute.</p>
  
  <p>I've tried @mudasbwa's suggestion:</p>
  
  <pre><code>includes(:photo, :video).where('photos.is_processing IS NULL').rank(:position_in_gallery)
  </code></pre>
  
  <p>but it gets me:</p>
  
  <blockquote>
    <p>ERROR: missing FROM-clause entry for table "photos"</p>
  </blockquote>