Symfony2 SoftDeleteable not working on QueryBuilder Delete

前端 未结 2 1820
感情败类
感情败类 2021-01-06 00:49

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

$entity = $this->em->getRepository(\'Users\')-         


        
2条回答
  •  盖世英雄少女心
    2021-01-06 01:33

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

    $query = $qb->getQuery()
    
    $query->setHint(
        \Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER,
        'Gedmo\SoftDeleteable\Query\TreeWalker\SoftDeleteableWalker'
    );
    
    $result = $query->getResult();
    

    Update:

    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.

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

    Test Usage: https://github.com/l3pp4rd/DoctrineExtensions/blob/master/tests/Gedmo/SoftDeleteable/SoftDeleteableEntityTest.php

提交回复
热议问题