diff --git a/docs/en/reference/working-with-associations.rst b/docs/en/reference/working-with-associations.rst index 85ffaee3a..f79371d16 100644 --- a/docs/en/reference/working-with-associations.rst +++ b/docs/en/reference/working-with-associations.rst @@ -453,11 +453,11 @@ following code: $user->addComment($myFirstComment); $em->persist($user); - $em->persist($myFirstComment); + $em->persist($myFirstComment); // mandatory if `persist` isn't set $em->flush(); Even if you *persist* a new User that contains our new Comment this -code would fail if you removed the call to +code requires the explicit call to ``EntityManager#persist($myFirstComment)``. Doctrine 2 does not cascade the persist operation to all nested entities that are new as well. @@ -500,6 +500,18 @@ and the "remove" operation. //... } +Now you can persist the `User` entity like that: + +.. code-block:: php + + addComment($myFirstComment); + + $em->persist($user); + $em->flush(); + Even though automatic cascading is convenient it should be used with care. Do not blindly apply cascade=all to all associations as it will unnecessarily degrade the performance of your application.