2013-07-11 19 views
11

Symfony2 (2.3.0) aracılığıyla Doctrine (2.2.3+) kullanarak veritabanımda bulunan nesneler üzerinde ManyToOne/OneToMany ilişkileri kurmaya çalışıyorum ve garip bir hata alıyorum. İşte nesnelerin ilgili kısımları (bir ürüne fazla özellik) şunlardır:Doctrine OneToMany ilişki hatası

/** 
* 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; 
} 

ben aşağıdaki hatayı alıyorum

php app/console doctrine:generate:entities BundleName 

komutu çalıştırdığınızda: Ben

[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? 

Doküman dokümanlarından baktı ve ManyToOne/OneToMany eşleştirmeleri için "kullanım" ifadesine herhangi bir başvuru görmüyor. Ne oluyor?

cevap

43

Ek açıklamalarınızın sözdizimi tamamlanmadı.

Aşağıdaki herhangi bir doktrin açıklaması için uygun sözdizimini görebilirsiniz.

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

Durumunuza göre, aşağıdaki gibi görünmelidir.

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

Ayrıca ProductAttributes varlıktaki açıklamaları düzeltmek isteyecektir.

+0

Teşekkürler! Hala Symfony 2.7.3 ile çalışmak –