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;
    }
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题