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"문에 대한 참조를 보지 못했습니다. 무슨 일 이니?
고마워요! 아직 Symfony 2.7.3을 사용하고 있습니다. –