我有实体答案,并对它们使用softdeleted
过滤器。当我在某些操作中删除实体时,一切都很好,我有一个deletedAt
日期时间。但是当我尝试在OnFlushEvent
中删除此实体时,我的实体就从数据库中消失了,为什么?
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);
}
}
}
实体
* @Gedmo\SoftDeleteable(fieldName="deletedAt")
*/
class QuestionAnswers
配置服务
app.doctrine_listener:
class: AppBundle\Listener\DoctrineListener
calls:
- [setContainer, ['@service_container']]
tags:
- { name: doctrine.event_subscriber, connection: default }
我查看了一下,这个过滤器已经启用了,我尝试强制启用但没有帮助