title: How does Doctrine2 One-To-Many fetch=EAGER work?
body: <p>I'm using Symfony 2.8 / Doctrine ORM 2.5.2.</p>
  
  <p>I have 2 entities, <code>Gallery</code> OneToMany <code>File</code></p>
  
  <pre><code>class Gallery
  {
      /**
       * @var File[]
       *
       * @ORM\OneToMany(targetEntity="File", mappedBy="gallery", fetch="EAGER")
       */
      private $files;
  }
  </code></pre>
  
  <p>I see 2 things in the documentation.</p>
  
  <p>First, now the OneToMany relationship does have the <code>fetch=EAGER</code> option (<a href="http://doctrine-orm.readthedocs.org/en/latest/reference/annotations-reference.html#onetomany" rel="noreferrer">specified here</a>). It was not there in previous versions.</p>
  
  <p>Second, the manual setting for this fetch method per query seems not available for OneToMany but I don't know if <a href="http://docs.doctrine-project.org/en/latest/reference/dql-doctrine-query-language.html#temporarily-change-fetch-mode-in-dql" rel="noreferrer">the documentation</a> is up-to-date as it states:</p>
  
  <blockquote>
    <p>Changing the fetch mode during a query is only possible for one-to-one
    and many-to-one relations.</p>
  </blockquote>
  
  <p>I have anyway tried both, here is my query:</p>
  
  <pre><code>public function findWithEager()
  {
      $qb = $this-&gt;createQueryBuilder('g');
  
      $query = $qb-&gt;getQuery();
      $query-&gt;setFetchMode("CommonBundle\\Entity\\Gallery", "files", ClassMetadata::FETCH_EAGER);
  
      return $query-&gt;getResult();
  }
  </code></pre>
  
  <p>But when I do:</p>
  
  <pre><code>foreach ($galleryRepository-&gt;findWithEager() as $gallery) {
      foreach ($gallery-&gt;getFiles() as $file) {
          $file-&gt;getId();
      }
  }
  </code></pre>
  
  <p>Then I got 1+n queries. The first is <code>SELECT * FROM Gallery</code> and the n following ones are <code>SELECT * FROM File WHERE id = :galleryId</code></p>
  
  <p>I would like Doctrine to do 1+1 queries, the second one being <code>SELECT * FROM File WHERE id IN (:galleryListIds)</code></p>
  
  <p>Did I miss something? Is this behavior implemented in Doctrine?</p>
  
  <p>The <a href="http://doctrine-orm.readthedocs.org/en/latest/changelog/migration_2_5.html#improve-efficiency-of-one-to-many-eager" rel="noreferrer">latest doctrine changelog</a> states:</p>
  
  <blockquote>
    <p>When marking a one-to-many association with fetch="EAGER" it will now
    execute one query less than before and work correctly in combination
    with indexBy.</p>
  </blockquote>
  
  <p>It is not clear at all what is the expected behavior.</p>
  
  <p>Any insight is welcome, thanks!</p>