title: exception id not found, dump show entity with isInitialized false and all attributes null
body: <p>I got a Cours (it's french for lesson) entity, and this entity have a "prof" attribute that is a manytoone relation with a Prof (teacher in french) entity. This Prof entity in itself extend an Eleve (student) entity (a prof is an eleve with more attributes and methods).</p>
  
  <p>I created a prof and a cours with fixtures, just to test my app. Then, in a CourseController, I tried to send my cours and prof informations to a view. To do so, I load my cours, then I try to access my prof through my cours.</p>
  
  <p>When I try to show the cours informations, everything is fine. But when I try to access the prof, nothing works anymore. I got an error that tells me that id column doesn't exists, and when I try to dump the prof, it tells me isInitialized is false, and every attributes is null.</p>
  
  <p>I found other stackoverflow (or other forums) topics with similar problems where people explain that symfony do lazy loading, and doesn't load the related entity this way it gets faster. But all solutions proposed doesn't work or aren't good choices in my case.</p>
  
  <p>One of the solution seems to be to set fetching to eager in my manytoone relation. But the problem is that prof itself has many manytoone or manytomany or other relations, and each of this entities has to allow access to entities related (so fetching eager too), and so, each time I'll want to get an entity, I'll load the entire database. And I just want to load what I need, which will change in each controller and each methods.</p>
  
  <p>Another solution proposed is to call some methods of my related object (prof in this situation), to tell doctrine we need to access it, this way doctrine load it. But this result with the exception again (telling id column is not found).</p>
  
  <p>in CoursController :</p>
  
  <pre><code>/**
   * @Route("/cours/{slug}", name="presentationCours")
   */
  public function presentationCours(Cours $cours)
  {
      $prof = $cours-&gt;getProf();
      // $prof-&gt;getLogin(); THIS result with exception
  
      dump($prof); // THIS shows all null values
  
      die();
  
      return $this-&gt;render('cours/presentation.html.twig', [
          "cours" =&gt; $cours,
          "prof" =&gt; $prof
      ]);
  }
  </code></pre>
  
  <p>note : if you wonder how I get the $cours var without telling symfony where to find it, it can find it just with the slug in the route. It's new in symfony 4 (not sure it's new but I think). I'm sure it works, I did it many times and a dump($cours) perfectly works.</p>
  
  <p>the twig file :</p>
  
  <pre><code>{% extends 'base.html.twig' %}
  
  {% block title %}{{ cours.nom }}{% endblock %}
  
  {% block body %}
  
      &lt;p&gt;
          {{ cours.nom }}
      &lt;/p&gt;
      &lt;p&gt;
          {{ cours.description }}
      &lt;/p&gt;
      &lt;p&gt;
          {{ prof.login }} {# THIS result with exception #}
      &lt;/p&gt;
  
  {% endblock %}
  </code></pre>
  
  <p>part of the Eleve entity (the entity which is parent of prof : prof extends eleve)</p>
  
  <pre><code>&lt;?php
  namespace App\Entity;
  
  use Doctrine\Common\Collections\ArrayCollection;
  use Doctrine\Common\Collections\Collection;
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * @ORM\Entity(repositoryClass="App\Repository\EleveRepository")
   */
  class Eleve
  {
      /**
       * @ORM\Id()
       * @ORM\GeneratedValue()
       * @ORM\Column(type="integer")
       */
      private $id;
  
      /**
       * @ORM\Column(type="string", length=255)
       */
      private $login;
  
      ...
  
  }
  </code></pre>
  
  <p>part of the prof entity :</p>
  
  <pre><code>&lt;?php
  
  namespace App\Entity;
  
  use App\Entity\Eleve;
  use Doctrine\Common\Collections\ArrayCollection;
  use Doctrine\Common\Collections\Collection;
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * @ORM\Entity(repositoryClass="App\Repository\ProfRepository")
   */
  class Prof extends Eleve
  {
      /**
       * @ORM\Id()
       * @ORM\GeneratedValue()
       * @ORM\Column(type="integer")
       */
      private $id;
  
      /**
       * @ORM\Column(type="text")
       */
      private $introduction;
  
      /**
       * @ORM\Column(type="text")
       */
      private $description;
  
      /**
       * @ORM\OneToMany(targetEntity="App\Entity\Cours", mappedBy="prof")
       */
      private $cours;
  </code></pre>
  
  <p>part of the cours entity :</p>
  
  <pre><code>&lt;?php
  
  namespace App\Entity;
  
  use Cocur\Slugify\Slugify;
  use Doctrine\ORM\Mapping as ORM;
  use Doctrine\Common\Collections\Collection;
  use Doctrine\Common\Collections\ArrayCollection;
  
  /**
   * @ORM\Entity(repositoryClass="App\Repository\CoursRepository")
   * @ORM\HasLifecycleCallbacks
   */
  class Cours
  {
      /**
       * @ORM\Id()
       * @ORM\GeneratedValue()
       * @ORM\Column(type="integer")
       */
      private $id;
  
      /**
       * @ORM\ManyToOne(targetEntity="App\Entity\Prof", inversedBy="cours")
       * @ORM\JoinColumn(nullable=false)
       */
      private $prof;
  </code></pre>
  
  <p>in the database with phpmyadmin :</p>
  
  <p>part of the cours table :</p>
  
  <p><a href="https://i.stack.imgur.com/DtM4i.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DtM4i.png" alt="cours table"></a></p>
  
  <p>part of the prof table :</p>
  
  <p><a href="https://i.stack.imgur.com/x3NaJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/x3NaJ.png" alt="prof table"></a></p>
  
  <p>the exception (without the dump) :</p>
  
  <p><a href="https://i.stack.imgur.com/XXkhI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XXkhI.png" alt="exception"></a></p>
  
  <p>the dump(prof) result :</p>
  
  <p><a href="https://i.stack.imgur.com/SZALq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SZALq.png" alt="prof"></a></p>
  
  <p>Thank you for your time.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Problem solved ! As jeroen told, the problem was about inheritance.</p>
  
  <p>Here is what I did to manage to solve it :</p>
  
  <pre><code>&lt;?php
  
  namespace App\Entity;
  
  use App\Entity\Prof;
  use App\Entity\Eleve;
  use Doctrine\ORM\Mapping as ORM;
  use Doctrine\ORM\Mapping\InheritanceType;
  use Doctrine\ORM\Mapping\DiscriminatorMap;
  use Doctrine\Common\Collections\Collection;
  use Doctrine\ORM\Mapping\DiscriminatorColumn;
  use Doctrine\Common\Collections\ArrayCollection;
  
  /**
   * @ORM\Entity(repositoryClass="App\Repository\EleveRepository")
   * @InheritanceType("SINGLE_TABLE")
   * @DiscriminatorColumn(name="discr", type="string")
   * @DiscriminatorMap({"eleve" = "Eleve", "prof" = "Prof"})
   */
  class Eleve
  {
  </code></pre>
  
  <p>I added the lines inheritancetype, discriminatorcolumn, and discriminatormap. This, because I chosed the <a href="https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/inheritance-mapping.html#class-table-inheritance" rel="nofollow noreferrer">class table inheritance</a>, but you could chose the <a href="https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/inheritance-mapping.html#mapped-superclasses" rel="nofollow noreferrer">mapped superclass</a> solution, or the <a href="https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/inheritance-mapping.html#single-table-inheritance" rel="nofollow noreferrer">single table inheritance</a> solution.</p>
  
  <p>For those who, like me, would have made a migration before changing the classes, I had a problem when I added the class table inheritance. Doctrine refused to migrate after that, an exception told me there was a foreign key problem. I'm not sure this is the good way, but I deleted my migration files in symfony (src > migrations), I droped my whole database in phpmyadmin, then in symfony, using CLI (command line interface, ctrl + ù on windows and ctrl + ` on mac (on the left of enter on the keyboard), I did : </p>
  
  <ul>
  <li>bin/console doctrine:database:create</li>
  <li>bin/console make:migration</li>
  <li>bin/console doctrine:migrations:migrate</li>
  </ul>
  
  <p>and the problem is now solved. But again, I'm really not sure this is the good way, just saying it worked for me.</p>