Doctrine 实体和 Zf2 模块依赖

Doctrine entity and Zf2 module dependancy

我有 2 个模块。

使用 ConfigEntity 和 使用 ReportingEntity

进行报告

这些实体具有 oneToManyRelation:

class Config
{
    public function __construct()
    {
        $this->reportings = new ArrayCollection();
    }

    /**
     * @ORM\OneToMany(targetEntity="Reporting\Entity\ConfigReporting",
     * mappedBy="config", cascade={"persist"}, orphanRemoval=true)
     */
    protected $reportings;
}

class ConfigReporting
{
    /**
     * @var int|null
     * @ORM\ManyToOne(targetEntity="Config\Entity\Config", inversedBy="reportings")
     * @ORM\JoinColumn(name="config", referencedColumnName="idConfig", onDelete="CASCADE")
     */
    protected $config;

}

我的报告模块依赖 Config 的模块才能工作。但是有了这个学说的映射,我有循环依赖吗?

如果是,我是否必须将报告实体声明到配置模块中?

这应该不是问题。

你试过像你展示的那样设置 类 吗?你 运行 遇到任何问题了吗?

更新

您可以将映射更改为单向。然后你就可以毫无问题地关闭你的报告模块。缺点是您的 Config 实体不会意识到关联...

class Config
{
    public function __construct()
    {

    }
}

class ConfigReporting
{
    /**
     * Unidirectional mapping owning side.
     *
     * @var int|null
     * @ORM\ManyToOne(targetEntity="Config\Entity\Config")
     * @ORM\JoinColumn(name="config", referencedColumnName="idConfig", onDelete="CASCADE")
     */
    protected $config;
}