0

我正在尝试创建 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不是。这里出了什么问题?我该如何解决这个问题?

4

1 回答 1

0

两者都应该反转,因为两者都是两个独立的 1:1 关系。并且只有拥有方(已反转)才会创建其列。

于 2014-11-12T01:04:39.663 回答