title: Symfony: Handling EntityNotFoundException on Doctrine relation
body: <p>When I tried to display a related object in Twig, and that relation is not present because the ID is in the parent entity, but the related entity was not in the current database, Symfony throws a 500 error</p>
  
  <blockquote>
    <p>// EntityNotFoundException  Twig_Error_Runtime
    An exception has been thrown during the rendering of a template
    ("Entity of type 'App\Entity\Location' for IDs id(265) was not
    found").</p>
  </blockquote>
  
  <p>I'd like to be able to ignore this error and instead display something like "Related object missing".   </p>
  
  <p>It seemed like this could be solved by some checking in Twig, but checking if the relation is null or not defined does not work - they both still find the relation, but when a property is called on the related entity, the exception is thrown.</p>
  
  <p>Has anyone solved this problem already?</p>