dongyulian5801 2015-11-17 11:08
浏览 16
已采纳

symfony映射错误:反向和拥有的side字段不存在 - 即使我在两个类中都声明了它们

I followed the symfony doc here to create bidirectional relationship between two class partgroup(OneToMany) and partsub(ManyToOne)

I get this error message when I try to validate the doctrine schema

* 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.

And

[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

I tried cache:clear

I have looked everywhere stackholder and google but could not find any resolution.

  • 写回答

1条回答 默认 最新

  • doumang20060820 2015-11-17 11:51
    关注

    Your mappings are not correct. Proper mappings should be something like this:

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

    (I also modified your property names)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行