title: Doctrine: Eager load the relationships of a lazy relationship?
body: <p>I am using Doctrine 2 to map an academic schedule.  Here's a simplified look at the relationships:</p>
  
  <ul>
  <li>A <strong>class</strong> has <strong>events</strong> (one-to-many)
  <ul>
  <li>An <strong>event</strong> has a <strong>type</strong> (many-to-one)</li>
  <li>An <strong>event</strong> has a <strong>location</strong> (many-to-one)</li>
  </ul></li>
  </ul>
  
  <p>Using <code>$em-&gt;find()</code> I can fetch the <strong>class</strong> only, with lazy-loaded relations.  Or using DQL with joins, I can eager load the entire object graph.  Is there a solution that's in-between?</p>
  
  <p>I want to fetch a <strong>class</strong> with lazy-loaded relations, and then under certain conditions trigger an eager load of the <strong>event</strong> relationship and all the <strong>event</strong> properties.  So when I call something like <code>$class-&gt;getEventsHydrateAll()</code>, all of the <strong>events</strong> and <strong>event types</strong> and <strong>event locations</strong> will be hydrated at once.</p>
  
  <p>I think I could accomplish this by updating my <strong>event</strong> schema to flag the <strong>type</strong> and <strong>location</strong> relationships as <code>fetch="EAGER"</code>.  But I'd like to have control over when this deep hydration occurs.</p>
  
  <p>Here's one attempt I made in my <strong>class</strong> repository, but Doctrine is running individual queries to lookup each <strong>type</strong> and <strong>location</strong>.</p>
  
  <pre><code>$query = $this-&gt;_em-&gt;createQuery('
          SELECT c FROM My\Entity\Class c
          WHERE c.id = :classId
  ');
  $query-&gt;setParameter('classId', $classId)
        -&gt;setFetchMode('My\Entity\Event', 'type', 'EAGER')
        -&gt;setFetchMode('My\Entity\Event', 'location', 'EAGER');
  
  try {
      return $query-&gt;getSingleResult();
  } catch (\Doctrine\ORM\NoResultException $e) {
      return NULL;
  }
  </code></pre>
  
  <p>Does anyone know if Doctrine supports this?  Thanks!</p>