FOSUserBundle One-To-One mapped Entity not saved

早过忘川 提交于 2019-12-21 06:19:40

问题


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.

  • UserEntity Gist- https://gist.github.com/ajaypatelbardoli/2f0c81cbdf3b0d136785

  • ProfileEntity Gist - https://gist.github.com/ajaypatelbardoli/fd02025fd338ed90545e

  • ProfileFormType gist - https://gist.github.com/ajaypatelbardoli/18ef99a3d0bd1198debc

  • RegistratonFormType Gist - https://gist.github.com/ajaypatelbardoli/09c047425032391c2445


回答1:


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.



来源:https://stackoverflow.com/questions/26303636/fosuserbundle-one-to-one-mapped-entity-not-saved

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!