我试图通过 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 配对的“use”语句的引用。到底是怎么回事?
您的注释语法不完整。
您可以在下面看到任何学说注释的正确语法。
/**
* @ORM\********
*/
因此,就您的情况而言,它应该如下所示。
/**
* @ORM\OneToMany(targetEntity="ProductAttributes", mappedBy="product")
*/
您还需要修复中的注释ProductAttributes
entity.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)