2014-01-15 2 views
2

ZF2 및 Doctrine으로 작업 중. 2. 엔티티 관리자를 사용하여 데이터를 삽입하려고 시도했습니다.Doctrine 2 "연관되어 있지만 예상되는 유형의 엔티티가 있습니다"

$link = new Link(); 
$link->title = 'aa'; 
$link->category_id = array('1'); 
$link->link_type_id = array('1'); 
$link->description = 'adsfa'; 
$link->webpage_url = 'asdfad'; 
$link->short_description = 'aa'; 
$link->email = 'asdf'; 
$link->meta_keys = 'asdf'; 
$link->date_created ='2014-01-14 13:26:54'; 


$this->getObjectManager()->persist($link); // ????? 
$this->getObjectManager()->flush(); 

저를 제공합니다 :이 때

class Link 
{ 
    /** 
    * @ORM\Id 
    * @ORM\GeneratedValue(strategy="AUTO") 
    * @ORM\Column(type="integer") 
    */ 
    protected $link_id; 

    /** @ORM\Column(type="string", length=255, nullable=false) */ 
    protected $title; 

    /** @ORM\Column(type="string", length=255, nullable=false) */ 
    protected $short_description; 

    /** @ORM\Column(columnDefinition="LONGTEXT NOT NULL") */ 
    protected $description; 

    /** @ORM\Column(type="string", length=255, nullable=false) */ 
    protected $webpage_url; 

    /** @ORM\Column(type="string", length=255, nullable=false) */ 
    protected $email; 

    /** @ORM\Column(type="string", length=255, nullable=false) */ 
    protected $meta_keys; 

    /** @ORM\Column(type="datetime", columnDefinition="DATETIME NOT NULL") */ 
    protected $date_created; 

    /** 
    * @ORM\ManyToOne(targetEntity="Schema\Entity\Category") 
    **/ 
    private $category_id; 

    public function __get($property) { 
     if (property_exists($this, $property)) { 
       return $this->$property; 
     } 
    } 

    public function __set($property, $value) { 
     if (property_exists($this, $property)) { 
      $this->$property = $value; 
     } 
     return $this; 
    } 
} 

그리고이

class LinkType 
{ 
    /** 
    * @ORM\Id 
    * @ORM\GeneratedValue(strategy="AUTO") 
    * @ORM\Column(type="integer") 
    */ 
    protected $link_type_id; 

    /** @ORM\Column(type="string", length=255, nullable=false) */ 
    protected $name; 

    public function __get($property) { 
     if (property_exists($this, $property)) { 
       return $this->$property; 
     } 
    } 

    public function __set($property, $value) { 
     if (property_exists($this, $property)) { 
      $this->$property = $value; 
     } 
     return $this; 
    } 
} 

:

나는이 법인이 오류 : 연결 스키마 \ 엔티티 \ 링크 #의 CATEGORY_ID에 유형의 찾을 개체,하지만 기대 스키마 \ 엔티티 \ 카테고리

나는 또한 퍼팅 시도 캐스케이드 = { "계속"} annontations에서하지만 나에게 오류를 제공합니다 클래스 ' '이 (가) 존재하지 않습니다.

왜?

답변

3

당신은 Schema\Entity\Category[]의 값으로 CATEGORY_ID를 설정해야하지 array()

+0

조금 혼란. 내가 어떻게 할 수 있니? 나는 다른 문자열 데이터와 함께 value = 1을'link' 엔티티로 전달하기를 원할뿐입니다. – Nikitas

+0

위의 질문에 사과드립니다. 당신은 정확하고 나는 데이터베이스 연합이 실제로하는 일을 모르고 있음을 깨달았습니다 ... 공부할 것입니다. 감사. – Nikitas

관련 문제