How to use another namespace class in Doctrine2 targetEntity mapping

When I establish the ManytoOne mapping, while both classes are in the same namespace, it works.

but it will not work if the two classes are in a different namespace?

/** * @ORM\ManyToOne(targetEntity="OP\ProjectBundle\Entity\Project", inversedBy="tickets") * @ORM\JoinColumn(name="project_id", referencedColumnName="id") */ protected $project; 
+4
source share
1 answer

You must use the absolute namespace of your target — pay attention to the leading backspace in its name.

 /** * @ORM\ManyToOne(targetEntity="\OP\ProjectBundle\Entity\Project", inversedBy="tickets") * @ORM\JoinColumn(name="project_id", referencedColumnName="id") */ protected $project; 
+8
source

All Articles