Symfony2: temporarily disable softdelete
I want to temporarily disable softdelete, so I can find deleted entities by ID and then really delete them in my unit tests (so to make sure I do not clog the database).
What I tried:
$this->em->getFilters()->disable('softdeletable');
$item = $repository->findOneById($id); //fetch the item which was soft-deleted
$this->em->remove($item);
$this->em->flush();
But that throws an error:
InvalidArgumentException : Filter 'softdeletable' is not enabled.
I also tried disable('soft-deletable') and disable('soft-deleteable') etc - nothing worked. But when I look at $this->em->getFilters(), the filter is THERE:
["enabledFilters"]=>
array(1) {
["softdeletable"]=>
string(48) "GedmoSoftDeleteableFilterSoftDeleteableFilter"
}
Trying the code without the disable of course doesn't work either:
DoctrineORMORMInvalidArgumentException : EntityManager#remove() expects parameter 1 to be an entity object, NULL given.
What am I doing wrong? I know I can really delete something with setting deletedAt to new DateTime but how do I delete an item without fetching it first?
Thanks for your help!
Originally a comment....
Are you using this in a loop or something?
If so, the filter may already be disabled.
You could do a check for whether it is enabled before disabling using if like...
$this->em->getFilters()->isEnabled('softdeleteable'))...
链接地址: http://www.djcxy.com/p/65038.html
上一篇: SoftDelete JTI实体与关联