FOSUserBundle一对一映射实体未保存 [英] FOSUserBundle One-To-One mapped Entity not saved

查看:134
本文介绍了FOSUserBundle一对一映射实体未保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于在实体FosUserBundle中实现一对一的问题。

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

用户实体有一对一映射与配置实体。我按照FOSUserBundle的文档所示覆盖了基本的RegistrationFormType。记录也保存在两个表中。但映射实体显示我的空白数据。请找到相同的被尊重的gist文件。

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.

ProfileEntity Gist - a href =https://gist.github.com/ajaypatelbardoli/fd02025fd338ed90545e =nofollow> https://gist.github.com/ajaypatelbardoli/fd02025fd338ed90545e

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

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

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

注册表格类型Gist - https://gist.github.com/ajaypatelbardoli/09c047425032391c2445

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

推荐答案

您的实现的问题是您不更新拥有方 Doctrine文档明确指出:

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.

在你的情况下,拥有方面是个人资料,您可以自动更新 setUserId() as folows:

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

您可以从关系双方访问数据,没有问题,Doctrine将查找相应的条目。

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

这篇关于FOSUserBundle一对一映射实体未保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆