如何在Doctrine2 targetEntity映射中使用不同的命名空间类 [英] How can I use a different namespace class in Doctrine2 targetEntity mapping
本文介绍了如何在Doctrine2 targetEntity映射中使用不同的命名空间类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我设置了一个ManytoOne映射,而两个类都在同一个命名空间中,它可以工作。
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;
推荐答案
您必须使用目标实体的绝对命名空间 - 注意其名称中的前导空格。
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;
这篇关于如何在Doctrine2 targetEntity映射中使用不同的命名空间类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文