Doctrine entity and Zf2 module dependancy

117 views Asked by At

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

There are 1 answers

6
Wilt On BEST ANSWER

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;
}