Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doctrine event listener and softdeleted filter #369

Open
shubaivan opened this issue Mar 17, 2018 · 1 comment
Open

Doctrine event listener and softdeleted filter #369

shubaivan opened this issue Mar 17, 2018 · 1 comment

Comments

@shubaivan
Copy link

I have entity answers and I use softdeleted filter for them, and when I remove entity in some action everything fine, I have deletedAt datetime, but when I try remove this entity in OnFlushEvent my entity is gone from DB, why ?

 public function onFlush(OnFlushEventArgs $args)
{
    $em = $args->getEntityManager();
    $uow = $em->getUnitOfWork();
    $em->getFilters()->enable('softdeleteable');
    foreach ($uow->getScheduledEntityUpdates() as $entity) {
        if ($entity instanceof Questions) {
            $existAnswers = $this->container->get('app.repository.question_answers')
                ->findOneBy(['questions' => $entity]);
                        $em->remove($existAnswers);                                                          
        }
    }
}

entity

 * @Gedmo\SoftDeleteable(fieldName="deletedAt")
 */
class QuestionAnswers

I checked, this filter enabled, I try force enable but no helped

@shubaivan
Copy link
Author

shubaivan commented Apr 3, 2018

I found suggestion
I would set priotity on your subscriber in order to fire your events before SoftDeleteableListener ones

app.doctrine_listener:
    class: AppBundle\Listener\DoctrineListener
    calls:
        - [setContainer, ['@service_container']]
    tags:
        - { name: doctrine.event_subscriber, connection: default, priority: -256 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant