2015-09-25 42 views
0

有沒有辦法在formbuilder中禁用多對一的連接?Symfony2禁用manytoone如果不需要

例子: 我要地圖的菜單項,以一個內部路由,或者一個外部鏈接

所以 到另一個實體或類似http://www.google.de

實體的字符串:

/** 
* @ORM\ManyToOne(targetEntity="Unite\MenuBundle\Entity\unmenurouting", inversedBy="unmenus") 
* @ORM\JoinColumn(name="unmenurouting_id", referencedColumnName="id") 
**/ 
private $unmenurouting; 

/** 
* @ORM\ManyToOne(targetEntity="Unite\MenuBundle\Entity\unmenu", inversedBy="unsubmenus") 
* @ORM\JoinColumn(name="unparentmenu_id", referencedColumnName="id") 
**/ 
private $unmenu; 

Formbuilder

->add('unmenu','entity',array(
       'class' => 'UniteMenuBundle:unmenu' , 
       'property' => 'unname' , 
       'multiple' => false , 
       'query_builder' => function(EntityRepository $er){ 
        return $er->createQueryBuilder('m') 
           ->where('m.unmain = 1') 
           ->andwhere('m.unactive = 1') 
           ; 
       } 
     )) 

現在,我得到一個錯誤發現協會MyBundle \ MenuBundle \實體類型學說\ COMMON \收藏\ ArrayCollection中的實體\的umenu#unmenurouting

所以我直接的問題 - 這可能爲null多對一連接?

非常感謝

回答

0

解決方案那麼簡單......

public function setunmenurouting(Unite\MenuBundle\Entity\unmenurouting $unmenurouting = NULL) 
{ 
    if($unmenurouting !== NULL) 
     $this->unmenurouting = $unmenurouting; 
    $this->unmenurouting = NULL; 
}