title: Doctrine2 (Doctrine 2.1) eager loading in Symfony2
body: <p>Let's say I have two entities in my Symfony2 project : <code>Category</code> and <code>Article</code> (a category having many articles).</p>
  
  <p>In my <code>CategoryRepository</code>, I have this method:</p>
  
  <pre><code>findAllDummy(){
    return $this-&gt;createQueryBuilder('c')
                -&gt;leftJoin('c.Articles a')
                -&gt;getQuery()-&gt;getResult();
  }
  </code></pre>
  
  <p>If I remember well, in Symfony1.4 (and the corresponding version of Doctrine), the returned objects would have their 'articles' attribute filled by the corresponding <code>Article</code> objects.
  Now, in Symfony2, Proxy objects are returned.</p>
  
  <p>So if I loop through a specific category's articles, As many queries as iterations will be executed.</p>
  
  <pre><code>foreach($category-&gt;getArticles() as $article){
    echo $article-&gt;getDoctrine()
                 -&gt;getRepository('')getTitle();
  }
  </code></pre>
  
  <p>I understand this is Doctrine2.1's default lazy loading behavior.</p>
  
  <p><strong>Question 1:</strong> how is this a better solution?
  N queries instead of 1.</p>
  
  <p>I tried to force eager loading by doing the following:</p>
  
  <pre><code>findAllDummy(){
    return $this-&gt;createQueryBuilder('c')
                -&gt;leftJoin('c.articles a')
                -&gt;getQuery()
                -&gt;setFetchMode('Category', 'articles', 'EAGER')
                -&gt;getResult();
  }
  </code></pre>
  
  <p>But the result remains the same.</p>
  
  <p><strong>Question 2:</strong> how to force eager loading in Doctrine2?</p>