OneToOne bidirectional self-referencing relationship, the first column not being created

671 views Asked by At

I'm trying to create 1:1 bidirectionl self-referencing relationship like this:

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;
    }

    ....

}

here is my xml mapping:

...

<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>

....

After updating the DB only binary_child_id is being created, and binary_parent_id not. What's going wrong here? How can I solve this?

1

There are 1 answers

0
Pradeep On

Both should be inversed-by since both are two separate 1:1 relationships. And only the owning side (having inversed-by) will have its column created.