bai*_*ano 11 one-to-many many-to-one symfony doctrine-orm
我试图通过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;
}
Run Code Online (Sandbox Code Playgroud)
我跑的时候
php app/console doctrine:generate:entities BundleName
Run Code Online (Sandbox Code Playgroud)
命令我收到以下错误:
[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?
Run Code Online (Sandbox Code Playgroud)
我查看了Doctrine文档,并没有看到对ManyToOne/OneToMany配对的"use"语句的任何引用.到底是怎么回事?
Tho*_*ire 44
您的注释语法不完整.
您可以在下面看到任何学说注释的正确语法.
/**
* @ORM\********
*/
Run Code Online (Sandbox Code Playgroud)
因此,在您的情况下,它应如下所示.
/**
* @ORM\OneToMany(targetEntity="ProductAttributes", mappedBy="product")
*/
Run Code Online (Sandbox Code Playgroud)
您还需要修复ProductAttributes实体中的注释.
| 归档时间: |
|
| 查看次数: |
13472 次 |
| 最近记录: |