我正在尝试创建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。这里出了什么问题?我该如何解决这个问题呢?
发布于 2014-11-12 09:04:40
两者都应该是反转的,因为它们都是两个独立的1:1关系。并且只有拥有方(已反转)才会创建它的列。
https://stackoverflow.com/questions/26873222
复制相似问题