Ajay Patel
Ajay Patel

Reputation: 791

FOSUserBundle One-To-One mapped Entity not saved

Hi Folks i have a question regarding implementing One-To-One in Entity FosUserBundle.

User Entity Has One To One Mapping With Profile Entity. I have override the basic RegistrationFormType as per shown in the FOSUserBundle's documentation. record is also saved in both table. but mapping entities show me blank data. Please find respected gist file for same.

Upvotes: 2

Views: 619

Answers (1)

andy
andy

Reputation: 2002

The problem with your implementation is that you do not update the owning side of the bidirectional association. The Doctrine documentation explicitly states:

See how the foreign key is defined on the owning side of the relation, the table Cart.

In your case the owning side is Profile which you can update automatically in setUserId() as folows:

public function setUserId(\XXXX\Bundle\UserBundle\Entity\User $userId = null)
{
    $this->userId = $userId;
    $userId->setProfile($this);

    return $this;
}

You can access the data from both sides of the relation without problems, Doctrine will look up the corresponding entries.

Upvotes: 1

Related Questions