[英]How to map user_id field to other tables Symfony FOSUserBundle
How do I map user_id field from user table to other tables. 如何将用户表中的user_id字段映射到其他表。 I am using Symfony2 and FOSUserBundle. 我正在使用Symfony2和FOSUserBundle。
I have already tried by this way 我已经尝试过这种方式
My Contacts Entity 我的联系人实体
/*
* @ORM\ManyToOne(targetEntity="User", inversedBy="contacts")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
protected $user;
My User Entity 我的用户实体
/**
* @ORM\OneToMany(targetEntity="Contacts", mappedBy="user")
*/
protected $contact;
I did 我做了
doctrine:schema:update --force
Nothing to update - your database is already in sync with the current entity metadata.
There should be user_id field added to contacts table. 应该将user_id字段添加到联系人表。
I tried adding cascade -- Ref Link 我尝试添加级联- 参考链接
/**
* @ORM\OneToMany(targetEntity="Contacts", mappedBy="user",cascade={"persist"})
*/
protected $contact;
But even that is not helping. 但这甚至无济于事。
In your contact entity 在您的联系实体中
/*
* @ORM\ManyToOne(targetEntity="User", inversedBy="contacts")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
protected $user;
It should be 它应该是
/**
* @ORM\ManyToOne(targetEntity="User", inversedBy="contacts")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
protected $user;
Missing extra star in doc block 文件区块中缺少多余的星号
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.