我正在尝试创建 1:1 双向自引用关系,如下所示:
class User extends AbstractUser implements UserInterface
{
.....
/**
* @var User
*/
private $binaryParent;
/**
* @var User
*/
private $binaryChild;
....
/**
* @return User
*/
public function getBinaryParent()
{
return $this->binaryParent;
}
/**
* @param UserInterface $user
* @return $this
*/
public function setBinaryParent(UserInterface $user)
{
$this->binaryParent = $user;
return $this;
}
/**
* @return User
*/
public function getBinaryChild()
{
return $this->binaryChild;
}
/**
* @param UserInterface $user
* @return $this
*/
public function setBinaryChild(UserInterface $user)
{
$this->binaryChild = $user;
return $this;
}
....
}
这是我的 xml 映射:
...
<one-to-one field="binaryParent" target-entity="SL\CoreBundle\Entity\User" mapped-by="binaryChild">
<join-column name="binary_parent_id" referenced-column-name="id" />
</one-to-one>
<one-to-one field="binaryChild" target-entity="SL\CoreBundle\Entity\User" inversed-by="binaryParent">
<join-column name="binary_child_id" referenced-column-name="id" />
</one-to-one>
....
更新后只binary_child_id
创建数据库,而binary_parent_id
不是。这里出了什么问题?我该如何解决这个问题?