symfony映射错误:反向和拥有侧字段不存在——尽管我在这两个类中都声明了它们


symfony mapping error : inverse and owning side field field doesnot exist - even though I declared them in both the classes

我在这里遵循symfony文档,在两个类partgroup(OneToMany)partsub(ManyToOne) 之间创建双向关系

当我试图验证条令模式时,我收到了这个错误消息

* The association Test'MyBundle'Entity'SpareParts'OemPartPosSubText#partgrpidk refers to the inverse side field Test'MyBundle'Entity'SpareParts'OemPartPosGrpText#partgrpidk which is not defined as association.
* The association Test'MyBundle'Entity'SpareParts'OemPartPosSubText#partgrpidk refers to the inverse side field Test'MyBundle'Entity'SpareParts'OemPartPosGrpText#partgrpidk which does not exist.

[Mapping]  FAIL - The entity-class 'Test'MyBundle'Entity'SpareParts'OemPartPosGrpText' mapping is invalid:
* The association Test'MyBundle'Entity'SpareParts'OemPartPosGrpText#partsubidk refers to the owning side field Test'MyBundle'Entity'SpareParts'OemPartPosSubText#partsubidk which is not defined as association, but as field.

代码

我试过cache:clear

我到处找stackholder和谷歌,但找不到任何解决方案。

您的映射不正确。正确的映射应该是这样的:

/**
 * OemPartPosGrpText
 *
 * @ORM'Table(name="oem_PartPosGrpText")
 * @ORM'Entity(repositoryClass="Test'MyBundle'Entity'SpareParts'Repo'SparePartMenuRepository")
 *
 */
class OemPartPosGrpText
{
    /**
     * @var integer
     *
     * @ORM'Column(name="PartGrpIDK", type="integer")
     * @ORM'Id
     * @ORM'GeneratedValue(strategy="IDENTITY")
     */
    private $partgrpidk;
     /**
     * @ORM'OneToMany(targetEntity="partSubText", mappedBy="partgrp")
     */
    private $partsubs;
    ...

/**
 * oemPartPosSubText
 *
 * @ORM'Table(name="oem_PartPosSubText")
 * @ORM'Entity(repositoryClass="Test'MyBundle'Entity'SpareParts'Repo'SparePartMenuRepository")
 */
 class partSubText
 {
    /**
     * @var integer
     *
     * @ORM'Column(name="PartSubIDK", type="integer")
     * @ORM'Id
     * @ORM'GeneratedValue(strategy="IDENTITY")
     */
    private $partsubidk;
    /**
     * @ORM'ManytoOne(targetEntity="OemPartPosGrpText",inversedBy="partsubs")
     * @ORM'JoinColumn(name="PartGrpIDK", referencedColumnName="PartGrpIDK")
     */
    private $partgrp;
    ...

(我还修改了您的房产名称)