symfony映射错误:反向和拥有的旁边字段字段不存在 - 即使我在两个类

时间:2015-11-17 11:08:22

标签: php symfony doctrine-orm

我按照symfony doc here创建了两个班级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.

Code

我尝试了cache:clear

我到处查看堆栈持有人和谷歌但找不到任何解决方案。

1 个答案:

答案 0 :(得分:0)

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

/**
 * 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;

    ...

(我也修改了你的属性名称)