【问题标题】:Understanding how owning side in a bidirectional relationship works了解双向关系中的拥有方如何工作
【发布时间】:2014-05-21 19:06:08
【问题描述】:

我正在使用php app/console doctrine:schema:validate 任务验证项目架构(代码不是我的,我只是想让它正常工作)。我可以看到的常见消息之一是:

  • 字段 Mapyet\AfiliadoBundle\Entity\Widget#negocio 位于双向关系的拥有方,但指定的 目标实体上的 mappedBy 关联 Mapyet\AfiliadoBundle\Entity\Negocio# 不包含所需的 'inversedBy' 属性。

这就是$negocioWidget.php 实体中的定义方式:

/**
 * @ORM\ManyToOne(targetEntity="Negocio", mappedBy="widget")
 */
private $negocio;

这就是$widgetNegocio.php 实体中的定义方式:

/**
 * @ORM\OneToMany(targetEntity="Widget", inversedBy="negocio")
 */
private $widget;

这个定义有什么问题?

【问题讨论】:

    标签: php symfony doctrine-orm entity


    【解决方案1】:

    反转它们:

    Widget.php

    /**
     * @ORM\ManyToOne(targetEntity="Negocio", inversedBy="widget")
     */
    private $negocio;
    

    Negocio.php

    /**
     * @ORM\OneToMany(targetEntity="Widget", mappedBy="negocio")
     */
    private $widget;
    

    http://docs.doctrine-project.org/en/2.0.x/reference/association-mapping.html#one-to-many-bidirectional

    【讨论】:

    • 这个AnnotationException: [Creation Error] The annotation @ORM\OneToMany declared on property Mapyet\AfiliadoBundle\Entity\Negocio::$widget does not have a property named "inversedBy". Available properties: mappedBy, targetEntity, cascade, fetch, orphanRemoval, indexBy
    • @ReynierPM 所以可能尝试执行rm -rf app/cache/dev 并再次运行./app/console d:s:v。你的代码看起来不错。
    • 这个真的很少见,现在 Profiler 说这个The association Mapyet\AfiliadoBundle\Entity\Negocio#widget refers to the inverse side field Mapyet\AfiliadoBundle\Entity\Widget#negocios which does not exist.
    • 这可能是因为拼写错误negocio 没有s 而不是negocios
    猜你喜欢
    • 2020-09-16
    • 1970-01-01
    • 2014-01-26
    • 2013-09-15
    • 1970-01-01
    • 2012-09-25
    • 2015-04-01
    • 2015-02-24
    • 1970-01-01
    相关资源
    最近更新 更多