• <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 中的分离实体错误

        Detached entity error in Doctrine(Doctrine 中的分离实体错误)
        <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 中的分离实体错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                  <tfoot id='vfsBR'></tfoot>

                        <legend id='vfsBR'><style id='vfsBR'><dir id='vfsBR'><q id='vfsBR'></q></dir></style></legend>
                          <tbody id='vfsBR'></tbody>
                        • <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>