EasyCorp / EasyAdminBundle

EasyAdmin is a fast, beautiful and modern admin generator for Symfony applications.
MIT License
4.09k stars 1.03k forks source link

SoftDeletable association issues #5779

Open BriceFab opened 1 year ago

BriceFab commented 1 year ago

Hello,

I'm currently facing an issue with the SoftDeletable filter in my project. I have an entity called 'Exercise' which has a 'mainExercise' association. https://github.com/doctrine-extensions/DoctrineExtensions/blob/main/doc/softdeleteable.md

The problem occurs when I delete an exercise that is referenced as the 'mainExercise' in another exercise. It throws the following error:

Entity of type 'Exercise' for IDs id(X) was not found.

On the frontend, I was able to resolve this error by setting the fetch mode to 'EAGER', which correctly loads the 'mainExercise' as null.

Is there a solution to this?


#[Gedmo\SoftDeleteable(fieldName: 'deletedAt', timeAware: false, hardDelete: true)]
class Exercises {

    #[ORM\ManyToOne(targetEntity: Exercise::class, fetch: 'EAGER')]
    #[ORM\JoinColumn(name: 'main_exercise_id', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
    private ?Exercise $mainExercise = null;

}

For super-admins, the SoftDeletable filter is disabled and it works as intended, which is expected. However, for other roles, I need to have the filter enabled on deleted entities in order not to display them.

    public function disableSoftDeleteableFilter(): void
    {
        if ($this->entityManager->getFilters()->isEnabled('softdeleteable')) {
            $this->entityManager->getFilters()->disable('softdeleteable');
        }
    }

Thank you for your attention

BriceFab commented 1 year ago

It's seems to be good by setting hardDelete to false:

#[Gedmo\SoftDeleteable(fieldName: 'deletedAt', timeAware: false, hardDelete: false)]

But, is it the right way to fix it 🤔

BriceFab commented 1 year ago

It's seems to be good by setting hardDelete to false:

#[Gedmo\SoftDeleteable(fieldName: 'deletedAt', timeAware: false, hardDelete: false)]

But, is it the right way to fix it 🤔

Update: this fix seems to only work on local environnement but not in production. Maybe due to caching