1
votes

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.

1

1 Answers

0
votes

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.