title: Get reference to JOINED Entity type
body: <p>I'm trying to figure out how to <code>getReference</code> on a class that HAS subclasses (in the sense that the Inheritance Type is set to JOINED on the parent class). I noticed that my application was doing 70 or so DB queries on every page load, and traced the issue back into the EntityManager class. The guilty code is below (this is in the <code>getReference</code> function, line 516 in my version, in the Doctrine\ORM\EntityManager class)</p>
  
  <pre><code>if ($class-&gt;subClasses) {
      return $this-&gt;find($entityName, $sortedId);
  }
  </code></pre>
  
  <p>Why does Doctrine do this? Is there any way around it? My entity that I'm trying to get a reference to is below...</p>
  
  <pre><code>/**
   * Advert
   *
   * @ORM\Table(name="main_advert")
   * @ORM\Entity(repositoryClass="API\CoreEntityBundle\Repository\AdvertRepository")
   * @ORM\InheritanceType("JOINED")
   * @ORM\DiscriminatorColumn(name="discriminator", type="integer")
   * @ORM\DiscriminatorMap({
   *      "0" = "Advert",
   *      "1" = "PropertyAdvert"
   * })
   */
  class Advert
  {
      /**
       * @var integer
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      protected $id;
  
  //Other stuff...
  }
  </code></pre>
  
  <p>And the code I tried to get a reference is this - </p>
  
  <pre><code>$advert = $this-&gt;get('doctrine.orm.default_entity_manager')
      -&gt;getReference('APICoreEntityBundle:Advert', array('id' =&gt; $id));
  </code></pre>
  
  <p>The only way I can think of to get a simple reference to the object without doing a DB call is to create a <code>setId()</code> function on the <code>Advert</code> class, but I know this isn't the correct way. </p>
  
  <p>Any help would be appreciated!</p>
  
  <p><strong>EDIT</strong> - OK, so I <strong>think</strong> I found the solution in the <code>getParialReference</code> function, just below the <code>getReference</code> function in the EntityManager class. I'm still interested as to why the manager need to do a <code>find</code> if the entity has children? </p>