• <bdo id='Ud39j'></bdo><ul id='Ud39j'></ul>
    <legend id='Ud39j'><style id='Ud39j'><dir id='Ud39j'><q id='Ud39j'></q></dir></style></legend>
  • <tfoot id='Ud39j'></tfoot>
  • <small id='Ud39j'></small><noframes id='Ud39j'>

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

      1. Symfony2 SoftDeleteable 不适用于 QueryBuilder 删除

        时间:2023-08-18

      2. <tfoot id='Cdpvu'></tfoot>
          • <bdo id='Cdpvu'></bdo><ul id='Cdpvu'></ul>

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

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

                  <legend id='Cdpvu'><style id='Cdpvu'><dir id='Cdpvu'><q id='Cdpvu'></q></dir></style></legend>
                  本文介绍了Symfony2 SoftDeleteable 不适用于 QueryBuilder 删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  Softdelete 行为在通过实体管理器执行删除语句时正常工作,如下代码:

                  Softdelete behavior works fine on execute delete statement via the entity manager as the following code:

                  $entity = $this->em->getRepository('Users')->find(7);
                  $this->em->remove($entity);
                  $this->em->flush();
                  

                  但是当通过 QueryBuilder 执行相同的功能时,硬删除将在数据库上执行

                  but when execute the same functionality via QueryBuilder hard delete will execute on database

                  $qb = $this->em->createQueryBuilder();
                  $qb->delete('Users', 'p');
                  $qb->where($qb->expr()->eq('p.id', ':id'));
                  $qb->setParameters(array("id" => 7));
                  $result = $qb->getQuery()->getResult();
                  

                  如何在所有情况下通过实体管理器或查询构建器允许软删除

                  How can I allow softdelete in all cases either via entity manager or query builder

                  推荐答案

                  如果您使用 DQL,那么您必须使用查询提示.这应该可以解决问题:

                  If you use DQL then you have to use a Query Hint. This should do the trick:

                  $query = $qb->getQuery()
                  
                  $query->setHint(
                      DoctrineORMQuery::HINT_CUSTOM_OUTPUT_WALKER,
                      'GedmoSoftDeleteableQueryTreeWalkerSoftDeleteableWalker'
                  );
                  
                  $result = $query->getResult();
                  

                  更新:

                  文档提到您必须使用查询提示,但没有提供示例,因此我从他们的测试中提取了用法.

                  The docs mention that you have to use a Query Hint but don't provide an example so I pulled the usage from their tests.

                  文档:https://github.com/l3pp4rd/DoctrineExtensions/blob/master/doc/softdeleteable.md

                  测试用法:https://github.com/l3pp4rd/DoctrineExtensions/blob/master/tests/Gedmo/SoftDeleteable/SoftDeleteableEntityTest.php

                  这篇关于Symfony2 SoftDeleteable 不适用于 QueryBuilder 删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:findBy 与 Symfony2 中的 JOIN 条件 下一篇:使用 Doctrine2 和 Symfony2 删除表格

                  相关文章

                • <tfoot id='XZLer'></tfoot>
                    <legend id='XZLer'><style id='XZLer'><dir id='XZLer'><q id='XZLer'></q></dir></style></legend>

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

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

                        <bdo id='XZLer'></bdo><ul id='XZLer'></ul>