duanji7182 2015-06-16 13:52
浏览 33
已采纳

Doctrine实体和Zf2模块依赖

I have 2 modules.

Config with ConfigEntity and Reporting with ReportingEntity

Those entities have a 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;

}

My module Reporting depends on Config's module to work. But with this doctrine's mapping, do i have a circular dependancy ?

If yes, do i have to declare the Reporting entity into Config module ?

  • 写回答

1条回答 默认 最新

  • duanchendu69495 2015-06-17 09:03
    关注

    This should not be a problem.

    Did you try to setup the classes like you show? Did you run into any problems?

    UPDATE

    You can change your mapping to Unidirectional. Then you can turn of your Reporting module without problems. The disadvantage is that your Config entity will not be aware of the association...

    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;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效