[英]Doctrine2, Symfony2 - oneToOne with multiple entities?
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.
我要做的是根据用户角色动态创建 oneToOne 关系。
So picture my 3 tables:所以想象一下我的 3 张桌子:
users (core table, username, pass, role etc, used for authentication)用户(核心表、用户名、通行证、角色等,用于身份验证)
users_admin用户管理员
users_client users_client
Then in my User.orm.yml I have:然后在我的 User.orm.yml 我有:
oneToOne:一对一:
--profile: - 轮廓:
----targetEntity: \UserBundle\Entity\Profile ----目标实体:\UserBundle\Entity\Profile
----mappedBy: user ----mappedBy:用户
The problem is I need the targetEntity to either be:问题是我需要 targetEntity 要么是:
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 .听起来你想要某种inheritance 。
The idea being that you have an (abstract) "Profile" entity, with concrete subclasses "UserProfile" and "AdminProfile".这个想法是你有一个(抽象的)“配置文件”实体,具有具体的子类“UserProfile”和“AdminProfile”。
Then your user has a oneToOne relationship with a "Profile", which can be of either type.然后,您的用户与“个人资料”建立了 oneToOne 关系,可以是任何一种类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.