2014-07-23 4 views
0

내 데이터 픽스처의 rootCommunication에 통신 파트를 추가하려고하면 오류가 없지만 데이터베이스 필드 'root_communication_id'에 NULL 만있다. 왜? 제 모델 '통신'자체 참조 엔티티에 관계를 저장할 수 없다.

/** 
* Communication 
* 
* @ORM\Table(name="communication") 
* @ORM\Entity(repositoryClass="Mother\BaseBundle\Entity\Repository\CommunicationRepository") 
*/ 
class Communication 
{ 
    /** 
    * @var integer 
    * 
    * @ORM\Column(name="id", type="integer") 
    * @ORM\Id 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    private $id; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="message", type="text", nullable=true) 
    */ 
    private $message; 

    /** 
    * @ORM\ManyToOne(targetEntity="Communication", inversedBy="childrenCommunication", cascade={"persist"}) 
    * @ORM\JoinColumn(name="root_communication_id", referencedColumnName="id", nullable=true) 
    * 
    */ 
    private $rootCommunication; 

    /** 
    * @ORM\OneToMany(targetEntity="Communication", mappedBy="rootCommunication") 
    * 
    */ 
    private $childrenCommunication; 

} 제 데이터 조명기에서

부품 이런 secound 조명기에 난 childrenCommunication을 추가 데이터베이스 세 통신을 첨가 rootCommunication.

 /** 
    * {@inheritDoc} 
    */ 
    public function load(ObjectManager $manager){ 

     $contentRepo = $this->container->get('doctrine')->getManager()->getRepository('MotherBaseBundle:Communication'); 


     $communication1 = $contentRepo->find($this->getReference('communication1')->getId()); 
     $communication1->addChildrenCommunication($this->getReference('communication2')); 
     $communication1->addChildrenCommunication($this->getReference('communication3')); 


     $manager->persist($communication1); 
     $manager->flush(); 
} 

답변

0

자녀를 추가 할 때 rootCommunication을 설정하지 않는 것으로 가정합니다.

당신은 추가 방법 등을 자동 세터를 추가해야

..

public function addChildrenCommunication(CommunicationInterface $communication) 
{ 
    if (!$this->childrenCommunication->contains($communication)) { 
     $this->childrenCommunication->add($communication); 
     $communication->setRootCommunication($this); 
    } 

    return $this; 
} 

.. 및 제거에 대해 동일한 ..