OneToMany相关实体未使用preUpdate侦听器进行更新

时间:2014-04-08 11:29:13

标签: symfony

我已经设置了一个带有preUpdate函数的事件监听器,我正在尝试使用它来更新通过OneToMany关系相关的地址实体。该函数运行,并且对象已更新,但这不会保留在数据库中。

您可以看到下面的代码,有没有人有任何想法?

public function preUpdate(LifecycleEventArgs $args){
    $entity = $args->getEntity();
    $entityManager = $args->getEntityManager();

    if ($entity instanceof Company) {

            $key = 0;
            $areaCode = explode(' ', $this->parsePostcode($entity->getAddresses()[$key]->getPostCode() ));
            $geo = $entityManager->getRepository('AlphaRMSBundle:SelGeo')->findOneByPostcode($areaCode[0]);


            if ($geo instanceof SelGeo) {
                $entity->getAddresses()[$key]->setEastings($geo->getEastings());
                $entity->getAddresses()[$key]->setNorthings($geo->getNorthings());
                $entity->getAddresses()[$key]->setLatitude($geo->getLatitude());
                $entity->getAddresses()[$key]->setLongitude($geo->getLongitude());
                $entity->getAddresses()[$key]->setMunicipality($geo->getTownCity());
                $entity->getAddresses()[$key]->setRegion($geo->getRegion());
                $entity->getAddresses()[$key]->setCountry($geo->getCountryString());
                $entity->getAddresses()[$key]->setCountryUkCode($geo->getCountryUkCode());
                //die($entity->getAddresses()[$key]->getMunicipality());
            }

    }
}

0 个答案:

没有答案