问题描述
我有一个用户实体和多个配置文件实体。我想要做的是根据用户角色动态创建一个OneToOne关系。所以图片我的3个表:
用户(核心表,用户名,密码,角色等等)用于身份验证
users_admin
users_client
然后在我的User.orm.yml我有:
oneToOne:
--profile:
- --targetEntity:\UserBundle\Entity\Profile
---- mappedBy:user
问题是我需要targetEntity或者是:
AdminProfile
ClientProfile
根据角色。有没有任何链接或建议?我完全失去了在哪里开始,欣赏任何有关如何实现这一点的输入。
听起来像你想要一些。
这个想法是你有一个(抽象的)Profile实体,具体的子类UserProfile和AdminProfile。
然后,您的用户与配置文件具有oneToOne关系,可以是任一类型。
I have a user entity, and multiple profile entities. What I'm trying to do is dynamically create a oneToOne relationship based on the user role.
So picture my 3 tables:
users (core table, username, pass, role etc, used for authentication)
users_admin
users_client
Then in my User.orm.yml I have:
oneToOne:
--profile:
----targetEntity: \UserBundle\Entity\Profile
----mappedBy: user
The problem is I need the targetEntity to either be:
AdminProfile
ClientProfile
Based on role. Is there any links or advice? I'm completely lost at where to start so appreciate any input on how I might achieve this.
Sounds like you want some kind of inheritance.
The idea being that you have an (abstract) "Profile" entity, with concrete subclasses "UserProfile" and "AdminProfile".
Then your user has a oneToOne relationship with a "Profile", which can be of either type.
这篇关于Doctrine2,Symfony2 - oneToOne与多个实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!