我正在尝试通过 Symfony2 (2.3.0) 使用 Doctrine (2.2.3+) 在我的数据库中的对象上设置一些 ManyToOne/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 配对的“使用”语句的任何引用。到底是怎么回事?