ApiPaltform – recover soft deleted element

$this->entityManager->getFilters()->disable(‘softdeleteable’);I’m using ApiPlatform and Symfony5

I’ve implemented softdelete on an entity User

This entity is softdeleted properly, I still want to displayed the deleted users for some roles, so I’m trying a DoctrineExtension to modify the request dynamically.

Here is my UserExtension.php:

    public function applyToItem(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, array $identifiers, string $operationName = null, array $context = []): void
        $this->addWhere($queryBuilder, $resourceClass);

    private function addWhere(QueryBuilder $queryBuilder, string $resourceClass): void

        if (User::class == $resourceClass &&
        ) {
            $rootAlias = $queryBuilder->getRootAliases()[0];

            $queryBuilder->andWhere("$rootAlias.deletedAt > '2019-01-01'");

I verified that I enter in the if condition.

But I still get a 404 on the item I’m trying to recover (which is still in base)

The same request entered in command line in the db return me the item I want to recover.

I’ve also tried to disable softdelete as follow :


But doing so disable it for the whole application, and I can’t re enable it in the UserExtension

Does anyone know what I’m doing wrong ? Or if there is another way to recover soft deleted items

Or if you got more docs on the subject I’d be gratefull cause I’m runnning out of options


Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *