From b11b16d8a69b05d3ae8214c434eb7ef44f17ff8f Mon Sep 17 00:00:00 2001 From: MohamedElKadaoui <42613994+MohamedElKadaoui@users.noreply.github.com> Date: Fri, 23 Nov 2018 15:21:20 +0100 Subject: [PATCH] Less code --- doctrine/associations.rst | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/doctrine/associations.rst b/doctrine/associations.rst index 5760509030b..b34acddd3bd 100644 --- a/doctrine/associations.rst +++ b/doctrine/associations.rst @@ -381,11 +381,7 @@ following method to the ``ProductRepository`` class:: WHERE p.id = :id' )->setParameter('id', $productId); - try { - return $query->getSingleResult(); - } catch (\Doctrine\ORM\NoResultException $exception) { - return null; - } + return $query->getOneOrNullResult(); } Now, you can use this method in your controller to query for a ``Product``