本文介绍了Symfony2 / Doctrine - postFlush的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果你看到我以前的问题,这是一种与之相关的一个新问题。所以我有一个实体,我有一个听众连接到这个。在我的createAction中,我创建了我的对象,然后将其刷新到我的数据库。在我的监听器中,我设置了一个postFlush函数

  public function postFlush(PostFlushEventArgs $ args)
{
$ em = $ args-> getEntityManager();

foreach($ em-> getUnitOfWork() - > getScheduledEntityDeletions()as $ entity){
if($ entity instanceof AvailabilityAlert){
var_dump(TEST );
$ this-> api_service-> addFlightsAction($ entity);
}
}
}

我正在努力做什么在这个函数中获取刚被刷新的实体。我已经尝试过getUnitsOfWork的所有不同的动作。 getScheduledEntityDeletions但是没有一个我可以进入var_dump发生的地方。



如何在这个postFlush函数中获取被刷新的实体?

解决方案

根据Doctrine2文档:您不能调用 PostFlush 事件。但是您可以拆分逻辑:使用 OnFlush 事件来获取这些实体,然后将其传递给 PostFlush 如果刷新成功。


If you saw my previous question, this is kind of linked to it but a new question. So I have an Entity and I have a listener linked up to this. In my createAction I create my Object and then persist-flush it to my database. In my listener, I have set up a postFlush function

public function postFlush(PostFlushEventArgs $args)
{
    $em = $args->getEntityManager();

    foreach ($em->getUnitOfWork()->getScheduledEntityDeletions() as $entity) {
        if ($entity instanceof AvailabilityAlert) {
            var_dump("TEST");
            $this->api_service->addFlightsAction($entity);
        }
    }
}

What I am trying to do in this function is get the entity that was just flushed. I have tried all the different actions of getUnitsOfWork e.g. getScheduledEntityDeletions but for none of them I can get into where the var_dump occurs.

How would I go about getting the flushed entity within this postFlush function?

解决方案

According to Doctrine2 documentation here : http://doctrine-orm.readthedocs.org/en/latest/reference/events.html you can't call the flushed entities on PostFlush event.

However you can split your logic : use the OnFlush event to get these entities and then pass it to the PostFlush if the flush succeeded.

这篇关于Symfony2 / Doctrine - postFlush的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-06 13:01