11

Symfony2 (2.3.0) 経由で Doctrine (2.2.3+) を使用してデータベース内のオブジェクトに ManyToOne/OneToMany 関係をセットアップしようとしていますが、奇妙なエラーが発生します。オブジェクトの関連部分は次のとおりです (1 つの製品に多くの属性があります)。

/**
 * 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" ステートメントへの参照が見当たりません。何が起こっている?

4

1 に答える 1

44

注釈の構文は完全ではありません。

以下の教義注釈の適切な構文を確認できます。

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

したがって、あなたの場合、次のようになります。

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

ProductAttributesエンティティの注釈も修正する必要があります。

于 2013-07-11T01:53:38.460 に答える