在实体中有可能有自引用字段吗?就像这样:
class Dir
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="integer")
*/
protected $parent; // reference to other Dir
}发布于 2015-10-24 08:52:48
普通联想与自我参照之间没有差异。
下列办法可能有效:
class Dir
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="Dir")
*/
private $parent;
}在Doctrine 这里中阅读更多有关关联的信息。
此外,如果不打算从实体继承,则应使用private属性。
https://stackoverflow.com/questions/33316088
复制相似问题