Skip to content

Instantly share code, notes, and snippets.

@joanfabregat
Last active March 24, 2023 17:02
Show Gist options
  • Save joanfabregat/58be0250706c891e1b66f3941708b217 to your computer and use it in GitHub Desktop.
Save joanfabregat/58be0250706c891e1b66f3941708b217 to your computer and use it in GitHub Desktop.
Get Doctrine Entity missing relation
<?php
/**
* @noinspection PhpRedundantCatchClauseInspection
* @noinspection PhpUnusedLocalVariableInspection
*/
public function getUser(): ?User
{
try {
$this->user?->getId();
return $this->user;
}
catch (EntityNotFoundException $e) {
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment