0

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 ?

Greco Jonathan
  • 2,517
  • 2
  • 29
  • 54

1 Answers1

1

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;
}
Wilt
  • 41,477
  • 12
  • 152
  • 203
  • i had no problem at all when i setup classes like this, but if I choose to deactivate Reporting, Mapping of Config can't work. Then Config need Reporting, and Reporting need Config, you see my point ? – Greco Jonathan Jun 17 '15 at 09:13
  • I understand your problem now, I will update my answer. – Wilt Jun 17 '15 at 09:16
  • You can also read [Keeping your Modules independent](http://doctrine-orm.readthedocs.org/en/latest/cookbook/resolve-target-entity-listener.html#keeping-your-modules-independent) chapter of Doctrine2. Maybe it can help you too? – Wilt Jun 17 '15 at 09:22
  • Yeah your link help me a lot, but I don't understand the last part. In zf2 context where i configure this...? – Greco Jonathan Jun 17 '15 at 09:40
  • @Hooli I guess that is up to you :) – Wilt Jun 17 '15 at 10:11
  • @copynpaste thanks for your help, your earned points for this – Greco Jonathan Jun 17 '15 at 11:53