2013-07-11 4 views
11

Symfoony2 (2.3.0)를 통해 Doctrine (2.2.3+)을 사용하여 데이터베이스의 개체에 ManyToOne/OneToMany 관계를 설정하려고하는데 이상한 오류가 발생했습니다. 다음은 객체의 관련 부분 (하나 개의 제품에 여러 속성)은 다음과 같습니다Doctrine OneToMany 관계 오류

/** 
* Product 
* 
* @ORM\Table(name="product") 
* @ORM\Entity 
*/ 
class Product 
{ 
    /** 
    * @var integer 
    * 
    * @ORM\Column(name="id", type="integer") 
    * @ORM\Id 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    protected $id; 

    ... 

    /** 
    * 
    * @OneToMany(targetEntity="ProductAttributes", mappedBy="product") 
    */ 
    protected $product_attributes; 

    public function __construct() { 
     $this->product_attributes = new \Doctrine\Common\Collections\ArrayCollection(); 
    } 
} 

/** 
* ProductAttributes 
* 
* @ORM\Table(name="product_attributes") 
* @ORM\Entity 
*/ 
class ProductAttributes 
{ 
    /** 
    * @var integer 
    * 
    * @ORM\Column(name="pa_id", type="integer") 
    * @ORM\Id 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    protected $pa_id; 

    /** 
    * @var integer 
    * 
    * @ORM\Column(name="product_id", type="integer") 
    */ 
    protected $product_id; 

    ... 

    /** 
    * 
    * @ManyToOne(targetEntity="Product", inversedBy="product_attributes") 
    * @JoinColumn(name="product_id", referencedColumnName="id") 
    */ 
    protected $product; 
} 

나는 다음과 같은 오류 얻을

php app/console doctrine:generate:entities BundleName 

명령을 실행하는 경우 : 내가 가지고있는

[Doctrine\Common\Annotations\AnnotationException]                            
[Semantical Error] The annotation "@OneToMany" in property LVMount\LVMBundle\Entity\Product::$product_attributes was never imported. Did you maybe forget to add a "use" statement for this annotation? 

을 Doctrine 문서를 살펴 보았고 ManyToOne/OneToMany 쌍에 대한 "use"문에 대한 참조를 보지 못했습니다. 무슨 일 이니?

답변

43

주석 구문이 완전하지 않습니다.

아래의 모든 독트린 어노테이션에 대한 올바른 구문을 볼 수 있습니다.

/** 
* @ORM\******** 
*/ 

따라서, 귀하의 경우는 다음과 같아야합니다.

/** 
* @ORM\OneToMany(targetEntity="ProductAttributes", mappedBy="product") 
*/ 

는 또한 ProductAttributes 엔티티에 주석을 수정하는 것이 좋습니다.

+0

고마워요! 아직 Symfony 2.7.3을 사용하고 있습니다. –

관련 문제