title: Optional Related Doctrine Entity (OneToOne Relationship)
body: <p>I have a OneToOne relationship between Image and ImageMetadata, where ImageMetadata is optional, but in the cases where the Image does not have a related meta-data record, the listing fails:</p>
  
  <pre><code>An exception has been thrown during the rendering of a 
  template ("Entity of type 'App\Entity\ImageMetadata' for IDs imageid(2043) was not found").
  </code></pre>
  
  <p>The twig call is simply</p>
  
  <pre><code>  {{ image.meta ? 'hasMeta' }} 
  </code></pre>
  
  <p>which becomes a call to $image->getMeta().</p>
  
  <p>I'm expecting it to return null if the related entity doesn't exist.</p>
  
  <p>Image.php defines metadata as optional:</p>
  
  <pre><code>class Image   
  {
  /**
  * @ORM\Column(type="integer", name="id")
  * @ORM\Id
  * @ORM\GeneratedValue
  */
  private $id;
  
  /**
   * @ORM\OneToOne(targetEntity="App\Entity\ImageMetadata", orphanRemoval=true, fetch="EAGER")
   * @ORM\JoinColumn(name="id", referencedColumnName="imageid", nullable=true)
   */
  
  private $meta;
  
  public function getMeta(): ?ImageMetadata
  {
      return $this-&gt;meta;
  }
  </code></pre>
  
  <p>ImageMetadata.php uses the same key ("imageid") </p>
  
  <pre><code>class ImageMetadata
  {
  
  /**
  * @ORM\Column(type="integer", name="imageid")
  * @ORM\Id
  */
  private $imageid;
  </code></pre>
  
  <p>Unfortunately, I don't have the option of tweaking the database, so I'm trying to define the Doctrine configuration to reflect the existing database and properly populate entities to use within the Symfony app.  The table definitions are:</p>
  
  <pre><code>   CREATE TABLE Images
                              (id INTEGER PRIMARY KEY, ...);
     CREATE TABLE ImageMetadata (imageid INTEGER PRIMARY KEY,...);
  </code></pre>
  
  <p>There are images without metadata, but I can't figure out how to simply have doctrine return null when I call $image->getMeta().  I've tried the suggestions I've found here and in other forums, setting EAGER, setting it to null initially, removing orphans, etc., but I must still be missing something.</p>
  
  <p>Thanks!</p>