Sonata Admin Bundle One-to-Many relationship not saving foreign ID

前端 未结 6 1344
粉色の甜心
粉色の甜心 2020-12-14 12:23

I have a problem with the SonataAdminBunle in combination with symfony 2.2. I have a Project entity and a ProjectImage entity and specified a One-to-Many relationship betwee

6条回答
  •  孤街浪徒
    2020-12-14 12:52

    You ca do it directly in the preUpdate function

        public function prePersist($societate)
    {
        $this->preUpdate($societate);
    }
    
    public function preUpdate($societate)
    {
        $conturi = $societate->getConturi();
        if (count($conturi) > 0) {
            foreach ($conturi as $cont) {
                $cont->setSocietate($societate);
            }
        }
    }
    

提交回复
热议问题