FOSUserBundle
FOSUserBundle copied to clipboard
Extending the extended User Class
I know it's possible to extend the BaseUser (in older versions of FOS and just the UserInterface in newer) when you create your own UserBundle in your vendor namespace.
Is it possible to extend that Extended User?
I understand that you have to specify the User Class in the fos_user config like this:
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: Acme\UserBundle\Entity\AcmeUser
Will this still work if you extend the AcmeUser?
For example, i'd like to keep different information for different roles in my application.
Employee extends AcmeUser Intern extends AcmeUser
(I'm not talking about user roles but actual different attributes per user class)
FOSUserBundle is not designed to work with entity inheritance (and you should probably avoid it as it is a performance killer for Doctrine as relational databases are bad at storing inheritance)
@stof Is there a solution for my use-case? Is it possible then to use different classes that implements the UserInterface and use them? Right now the only way I see it is to create different registration form types (and put all possible attributes in the User class) and handle the role assignment in the controller.
May I suggest as I used .. the system that I'm developing now I have 3 user types.
- Provider 1.1 Personal 1.2 Corporate
- Consumer
Thus I define the Provider as abstract and inherited the entity Personal and Corporate.
I'm also the type Consumer. Friendlier suggestion mentioned at the beginning of this review I suggest you add a property on the User entity that you can add its identifier, eg when you add vendor user_id = provider_id.
I hope it helps.
@stof does that include JOINED Table inheritance?
@sstok yes. FOSUserBundle needs to know the name of the entity class. As soon as you have multiple entities, it breaks as you have several classes.
I was actually talking about the performance impact ;) how much slower is it actually?
@sstok it forbids using lazy-loading in any place where you have a ToOne relation with the user as target
@sstok Is it still inadvisable to inherit the BaseUser class? Or has it changed since 2013?
@Fabuloops I am not using the FosUserBundle anymore, so I don't know :)