From f3b07bf20bc6773a31496a0404c644565691e624 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Fri, 19 Aug 2016 20:28:36 +0200 Subject: [PATCH 1/2] Explain what happens if `flush()` fails It should be mentioned *somewhere* in this chapter, how to verify that the entity has really been persisted. What's the best practice here? try...catch? Or (for INSERT) check if $entity->getId() does exist? => Please expand on that. Also, you could list all possible types of exceptions explicitly. --- doctrine.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doctrine.rst b/doctrine.rst index fbd87c757d2..2070040c031 100644 --- a/doctrine.rst +++ b/doctrine.rst @@ -555,6 +555,11 @@ Take a look at the previous example in more detail: ``Product`` objects and then subsequently call ``flush()``, Doctrine will execute 100 ``INSERT`` queries using a single prepared statement object. +.. note:: + + If ``flush()`` fails, an exception is thrown, which you can catch by wrapping + the ``flush()`` method in a ``try...catch`` block. + Whether creating or updating objects, the workflow is always the same. In the next section, you'll see how Doctrine is smart enough to automatically issue an ``UPDATE`` query if the entity already exists in the database. From 460b74a06ffca2b8acb6ffa3edaff5f499302b6f Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Mon, 29 Aug 2016 17:36:36 +0200 Subject: [PATCH 2/2] Integrated improvement by javiereguiluz --- doctrine.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doctrine.rst b/doctrine.rst index 2070040c031..7fde2a36cbf 100644 --- a/doctrine.rst +++ b/doctrine.rst @@ -557,8 +557,9 @@ Take a look at the previous example in more detail: .. note:: - If ``flush()`` fails, an exception is thrown, which you can catch by wrapping - the ``flush()`` method in a ``try...catch`` block. + If the ``flush()`` call fails, a ``Doctrine\ORM\ORMException`` exception + is thrown, which you can catch by wrapping the ``flush()`` method in a + ``try...catch`` block. Whether creating or updating objects, the workflow is always the same. In the next section, you'll see how Doctrine is smart enough to automatically