Подтвердить что ты не робот

Ошибка отношения доктрины OneToMany

Я пытаюсь установить некоторые отношения ManyToOne/OneToMany в объектах моей базы данных с помощью Doctrine (2.2.3+) через Symfony2 (2.3.0), и я получаю странную ошибку. Вот соответствующие части объектов (многие атрибуты для одного продукта):

/**
 * 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 и не вижу ссылки на инструкцию "use" для партию ManyToOne/OneToMany. Что происходит?

4b9b3361

Ответ 1

Синтаксис ваших аннотаций не завершен.

Вы можете увидеть правильный синтаксис для любой аннотации доктрины ниже.

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

Итак, в вашем случае это должно выглядеть следующим образом.

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

Вы также захотите исправить аннотации в объекте ProductAttributes.