Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use a different namespace class in Doctrine2 targetEntity mapping

Tags:

doctrine-orm

When I set a ManytoOne mapping, while both class in same namespace, it works.

but it won't work if the two class are in different namespace?

/**
 * @ORM\ManyToOne(targetEntity="OP\ProjectBundle\Entity\Project", inversedBy="tickets")
 * @ORM\JoinColumn(name="project_id", referencedColumnName="id")
 */
protected $project;
like image 616
Jayson Avatar asked Oct 07 '11 14:10

Jayson


1 Answers

You have to use the absolute namespace of your target entity - note the leading backspace in its name.

/**
 * @ORM\ManyToOne(targetEntity="\OP\ProjectBundle\Entity\Project", inversedBy="tickets")
 * @ORM\JoinColumn(name="project_id", referencedColumnName="id")
 */
protected $project;
like image 168
mkraemer Avatar answered Sep 29 '22 07:09

mkraemer