title: With many-to-many relationship, associated class data cannot be fetched with find method in doctrine and symfony2
body: <p>I am using doctrine with symfony2 framework. I have an entity 'Question' which can have multiple 'Theme's. So I defined this many-to-may relationship (also on the other hand Themes can have multiple Questions) in yml:</p>
  
  <pre><code>  manyToMany:
      themes:
        targetEntity: Theme
        joinTable:
          name: question_themes
          joinColumns:
            question_id:
              referencedColumnName: id
          inverseJoinColumns:
            theme_id:
              referencedColumnName: id
  </code></pre>
  
  <p>And inside the Question entity class:</p>
  
  <pre><code>private $themes;
  public function setThemes($themes) {
      $this-&gt;themes = $themes;
  }
  public function getThemes() {
      return $this-&gt;themes;
  }
  </code></pre>
  
  <p>Here, question_themes is a table(in MySQL) which holds the many-to-many relationship i.e.  question_id and theme_id.</p>
  
  <p>Now when I fetch question data by:</p>
  
  <pre><code>$questions = $this-&gt;getDoctrine()-&gt;getRepository('MyBundle:Question')-&gt;findAll();
  </code></pre>
  
  <p>or</p>
  
  <pre><code>$questions = $this-&gt;getDoctrine()-&gt;getRepository('MyBundle:Question')-&gt;findBy(
                  array('locale'=&gt;$locale),
                  array('createdAt' =&gt; 'DESC')
              );
  </code></pre>
  
  <p>etc. it fetches all the associated themes data along with questions i.e.</p>
  
  <pre><code>foreach($questions as $question) {
      foreach($question-&gt;getThemes() as $theme) {
          // some code
      }
  }
  </code></pre>
  
  <p>Everything seems perfect. But whenever I fetch the question data by:</p>
  
  <pre><code>$question = $this-&gt;getDoctrine()-&gt;getRepository('MyBundle:Question')-&gt;find($question_id);
  </code></pre>
  
  <p>or</p>
  
  <pre><code>$question = $this-&gt;getDoctrine()-&gt;getRepository('MyBundle:Question')-&gt;findById($question_id);
  </code></pre>
  
  <p>etc, then the associated theme data are not being fetched and thus I am getting error at the foreach loop:</p>
  
  <pre><code>foreach($question-&gt;getThemes() as $theme) {
      // some code
  }
  </code></pre>
  
  <p>Can anybody help on this, as I am new to doctrine and symfony2?</p>
  
  <p>Thanks</p>