title: Doctrine 2 Association Mapping Overhead?
body: <p>Association mapping in Doctrine 2</p>
  
  <pre><code>&lt;?php
  class User
  {
      //...
      /**
       * @ManyToMany(targetEntity="Group")
       * @JoinTable(name="User_Group",
       *      joinColumns={@JoinColumn(name="User_id", referencedColumnName="id")},
       *      inverseJoinColumns={@JoinColumn(name="Group_id", referencedColumnName="id")}
       *      )
       */
      private $groups;
      //...
  }
  </code></pre>
  
  <p>In test, assuming in this example $groups initialized as ArrayCollection() in constructor, returns all groups associated with the user.</p>
  
  <p>A programmer in my dev team brought up a good point about this scenario. It loads all groups associated with a user entity, we may not need all of them.</p>
  
  <p>When doing DQL join statements, lets say we want to select the favorite groups, achievable by DQL joins, we join user, group, and favorites. Does Doctrine queries all the groups again? This is the overhead I'm trying to point out, there's already an array collection of all the groups.</p>
  
  <p>How do we control the result from association mapping? Or if we remove association mappings, can we still use DQL to join entities that don't have association mappings setup? OR, does Doctrine actually use the data from the association mapping in DQL?</p>