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

        <tfoot id='eNRVU'></tfoot>

        Doctrine entitymanager clear 没有完全清除

        时间:2023-08-19
        1. <i id='VtRM1'><tr id='VtRM1'><dt id='VtRM1'><q id='VtRM1'><span id='VtRM1'><b id='VtRM1'><form id='VtRM1'><ins id='VtRM1'></ins><ul id='VtRM1'></ul><sub id='VtRM1'></sub></form><legend id='VtRM1'></legend><bdo id='VtRM1'><pre id='VtRM1'><center id='VtRM1'></center></pre></bdo></b><th id='VtRM1'></th></span></q></dt></tr></i><div id='VtRM1'><tfoot id='VtRM1'></tfoot><dl id='VtRM1'><fieldset id='VtRM1'></fieldset></dl></div>

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

            <bdo id='VtRM1'></bdo><ul id='VtRM1'></ul>
              <tbody id='VtRM1'></tbody>
            <legend id='VtRM1'><style id='VtRM1'><dir id='VtRM1'><q id='VtRM1'></q></dir></style></legend>

              1. <tfoot id='VtRM1'></tfoot>
                • 本文介绍了Doctrine entitymanager clear 没有完全清除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有这段代码:

                  $entityManager->clear('RezaMyBundleEntityListItem');
                  
                  $identity = $entityManager->getUnitOfWork()->getIdentityMap();
                  foreach ($identity as $class => $objectlist) {
                      if ($class == 'RezaMyBundleEntityListItem') {
                          print "didn't fully clear, exiting..
                   ";
                          exit;
                      }
                  }
                  

                  您会认为在我将类名传递给 clear 之后,您不应再在工作单元中看到这些对象,但是通过查看源代码,我注意到当您将参数传递给 clear() 函数,它只分离该类型的实体.另一方面,如果我不向 clear() 传递任何参数,它会分离并实际上清除,因此上面的代码不会到达第 138 行,退出.所以这意味着它不仅分离了所有实体,而且还清除了工作单元.

                  You would think that after I pass in the classname to clear, you should not see those objects in the unit of work anymore, but by looking at the source I noticed that when you pass an argument to the clear() function it only detaches entities of that type. On the other hand, if I don't pass any arguments to clear() it detaches and does in fact clear, so the above code does not hit line 138, exit. So that means it not only detaches all entities, but also clears the unit of work.

                  有人对此有什么想法吗?我应该在学说中提交错误吗?

                  Anyone has any thoughts on this? Should I file a bug with doctrine?

                  推荐答案

                  我想说,从技术上讲,这不是一个错误,因为 clear() 按照文档中的描述工作,请参阅 Doctrine2 API,文档 和 源代码:(当前版本).

                  I would say that technically it is not a bug as clear() works as described in the documentation, see Doctrine2 API, documentation and source code (current version).

                  clear() 方法只是一种detach() 指定类型的所有实体或实体的方法.它可以被认为是一个Multi-Detach",它的目的并不超出分离.

                  The clear() method is just a way to detach() all entities or entities of a specified type. It can be thought as a "Multi-Detach", its purpose does not extend past detaching.

                  当使用 clear() 分离所有实体时,Doctrine 使用最有效的方法分离实体.在这个过程中,身份映射数组被设置为一个空的array().这将使我相信您所指的内容看起来已清除.

                  When detaching all entities using clear() Doctrine detaches the entities using the most efficient method possible. In the process the Identity Map Array is set to an empty array(). This will give the appearance of what I believe you are referring to as cleared.

                  $entityManager->clear();
                  $identity = $entityManager->getUnitOfWork()->getIdentityMap(); 
                  //This will return a an empty array() to $identity
                  //therefore $identity['RezaMyBundleEntityListItem'] would be undefined
                  

                  如果我们假设为 RezaMyBundleEntityListItem 的实体检索了数据.那么在下面的例子中我们可以看到工作单元至少有 1 个 RezaMyBundleEntityListItem 对象.

                  If we assume that data was retrieved for an entity of RezaMyBundleEntityListItem. Then in the following example we can see that the unit of work has at least 1 RezaMyBundleEntityListItem object.

                  $identity = $entityManager->getUnitOfWork()->getIdentityMap();
                  $count = count($identity['RezaMyBundleEntityListItem']);
                  // $count would be > 0;
                  

                  但是,当您使用 clear($entityName) 并按实体类型清除时,已清除/分离的实体将从工作单元中删除,它只是数组键 [$entityName] 剩下的,不是任何对象.

                  However, when you use clear($entityName) and clear by entity type, the cleared/detached entities are removed from the unit of work, it is only the array key [$entityName] that remains, not any of the objects.

                  $entityManager->clear('RezaMyBundleEntityListItem');
                  $identity = $entityManager->getUnitOfWork()->getIdentityMap(); 
                  $count = count($identity['RezaMyBundleEntityListItem']);
                  //$count would be == 0. All Objects cleared/detached.
                  

                  此功能是文档指定的全部内容.

                  This functionality is all that is specified by the documentation.

                  我确实认为功能请求是为了使其更一致地工作.当调用 clear($entityName) Doctrine 应该 unset() 剩余的键,从而使其未定义(清除).这将使我们能够更轻松地编写代码,无论我们使用 clear() 还是 clear($entityName).

                  I do think a feature request is in order, to make it work more consistently. When invoking clear($entityName) Doctrine should unset() the remaining key thereby making it undefined (cleared). This would allow us to more easily write code that would work whether we used clear() or clear($entityName).

                  这篇关于Doctrine entitymanager clear 没有完全清除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用没有实体类的本机 SQL 查询 下一篇:如何在 Doctrine2 (Symfony2) 中按案例排序

                  相关文章

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

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

                      <legend id='Embkg'><style id='Embkg'><dir id='Embkg'><q id='Embkg'></q></dir></style></legend>