• <legend id='UqmWM'><style id='UqmWM'><dir id='UqmWM'><q id='UqmWM'></q></dir></style></legend>
      <i id='UqmWM'><tr id='UqmWM'><dt id='UqmWM'><q id='UqmWM'><span id='UqmWM'><b id='UqmWM'><form id='UqmWM'><ins id='UqmWM'></ins><ul id='UqmWM'></ul><sub id='UqmWM'></sub></form><legend id='UqmWM'></legend><bdo id='UqmWM'><pre id='UqmWM'><center id='UqmWM'></center></pre></bdo></b><th id='UqmWM'></th></span></q></dt></tr></i><div id='UqmWM'><tfoot id='UqmWM'></tfoot><dl id='UqmWM'><fieldset id='UqmWM'></fieldset></dl></div>

        <bdo id='UqmWM'></bdo><ul id='UqmWM'></ul>
    1. <small id='UqmWM'></small><noframes id='UqmWM'>

    2. <tfoot id='UqmWM'></tfoot>

        Doctrine 中的分离实体错误

        时间:2024-08-15
        <tfoot id='lQou5'></tfoot><legend id='lQou5'><style id='lQou5'><dir id='lQou5'><q id='lQou5'></q></dir></style></legend>
          <i id='lQou5'><tr id='lQou5'><dt id='lQou5'><q id='lQou5'><span id='lQou5'><b id='lQou5'><form id='lQou5'><ins id='lQou5'></ins><ul id='lQou5'></ul><sub id='lQou5'></sub></form><legend id='lQou5'></legend><bdo id='lQou5'><pre id='lQou5'><center id='lQou5'></center></pre></bdo></b><th id='lQou5'></th></span></q></dt></tr></i><div id='lQou5'><tfoot id='lQou5'></tfoot><dl id='lQou5'><fieldset id='lQou5'></fieldset></dl></div>

          <small id='lQou5'></small><noframes id='lQou5'>

                  <bdo id='lQou5'></bdo><ul id='lQou5'></ul>
                    <tbody id='lQou5'></tbody>
                • 本文介绍了Doctrine 中的分离实体错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我将一组实体发布到控制器,我想删除所有这些实体.但是,下面的代码会引发 A detached entity was found during removed MyProjectBundleMyBundleEntityMyEntity@000000004249c13f00000001720a4b59 错误.我哪里错了?

                  I am posting an array of entities to a controller, all of which I'd like to delete. However, the below code throws an A detached entity was found during removed MyProjectBundleMyBundleEntityMyEntity@000000004249c13f00000001720a4b59 error. Where am I going wrong?

                  $doctrineManager = $this->getDoctrine()->getManager();
                  foreach ($form->getData()->getEntities() as $entity) {
                      $doctrineManager->merge($entity);  
                      $doctrineManager->remove($entity);
                  }
                  $doctrineManager->flush();
                  

                  推荐答案

                  你应该对处于 detached 状态的实体使用 merge 操作并且你想把它们放到托管状态.

                  You should use merge operation on entities which are in detached state and you want to put them to managed state.

                  合并应该像这样$entity = $em->merge($detachedEntity).之后 $entity 指的是合并操作返回的完全托管副本.因此,如果您的 $form 包含 分离的 实体,您应该像这样调整您的代码:

                  Merging should be done like this $entity = $em->merge($detachedEntity). After that $entity refers to the fully managed copy returned by the merge operation. Therefore if your $form contains detached entities, you should adjust your code like this:

                  $doctrineManager = $this->getDoctrine()->getManager();
                  foreach ($form->getData()->getEntities() as $detachedEntity) {
                      $entity = $doctrineManager->merge($detachedEntity);  
                      $doctrineManager->remove($entity);
                  }
                  $doctrineManager->flush();
                  

                  但是,如果 $form 不包含 detached 实体,则应删除 merge 操作,如下所示:

                  However, in case that the $form does not contain detached entities, you should remove the merge operation, like this:

                  $doctrineManager = $this->getDoctrine()->getManager();
                  foreach ($form->getData()->getEntities() as $entity) {
                      $doctrineManager->remove($entity);
                  }
                  $doctrineManager->flush();
                  

                  这张图片应该可以帮助您了解实体状态转换.它取自 Java Persistence API,但在 Doctrine2 中大致相同.

                  This image should help you to understand entity state transitions. It is taken from Java Persistence API, but in Doctrine2 it is about the same.

                  这篇关于Doctrine 中的分离实体错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 symfony 和 MAMP 时出现 PDO 连接错误 下一篇:原则 2:无法更新 SQL Server 2008apm 上的 DateTime 列

                  相关文章

                  <tfoot id='vfsBR'></tfoot>

                    <legend id='vfsBR'><style id='vfsBR'><dir id='vfsBR'><q id='vfsBR'></q></dir></style></legend>
                    • <bdo id='vfsBR'></bdo><ul id='vfsBR'></ul>

                      <small id='vfsBR'></small><noframes id='vfsBR'>

                      <i id='vfsBR'><tr id='vfsBR'><dt id='vfsBR'><q id='vfsBR'><span id='vfsBR'><b id='vfsBR'><form id='vfsBR'><ins id='vfsBR'></ins><ul id='vfsBR'></ul><sub id='vfsBR'></sub></form><legend id='vfsBR'></legend><bdo id='vfsBR'><pre id='vfsBR'><center id='vfsBR'></center></pre></bdo></b><th id='vfsBR'></th></span></q></dt></tr></i><div id='vfsBR'><tfoot id='vfsBR'></tfoot><dl id='vfsBR'><fieldset id='vfsBR'></fieldset></dl></div>