Matching a Doctrine association between objects in different packages or linking objects from two different packages?

Region:

namespace Acme\RegionBundle\Entity; class Region { private $id; /** * @ORM\OneToMany(targetEntity="User") * @ORM\JoinColumn(name="region_id", referencedColumnName="id") */ private $users; } 

User:

 namespace Acme\UserBundle\Entity; class User { private $id; private $region_id; } 

How to link objects from different packages without mentioning the fully specified path of the entity, i.e. hard coding.

Is there a better approach?

Can "Allow target receiver" . I could not understand how this can be applied here?

+4
source share
1 answer

The target listener allows you to redefine associations at run time. This allows you to basically display something like the following:

 @ORM\OneToMany(targetEntity="My\Namespace\UserInterface") 

As you can see, mapping an interface as a target does not make much sense. This becomes really useful when you say that every My\Namespace\UserInterface should be replaced with a link Other\Namespace\User .

+6
source

All Articles