如何在docline onFlush Listener中进行事务性createQueryBuilder?

时间:2016-03-15 20:36:41

标签: php doctrine-orm doctrine

我对doctrine listener [onFlush]有问题。我需要更新包含在事务中的其他实体。当我像这个例子一样使用时,更新在事务之前运行。可以帮助我吗?

public function onFlush(OnFlushEventArgs $args)
{
    $ea = $this->getEventAdapter($args);
    $om = $ea->getObjectManager();
    $uow = $om->getUnitOfWork();

    foreach ($ea->getScheduledObjectUpdates($uow) as $object) {

        //... some operation on entity
        $uow->propertyChanged($object, 'field', 'oldValue', 'newValue');
        //...........................

        // global update with createQueryBuilder on another entities
        // I need added this also to transaction
        $qb = $om->createQueryBuilder();
        $qb->update(".........")
            ->set(".........")
            ->where(".........")
            ->getQuery()
            ->execute();
    }
}

0 个答案:

没有答案