FriendsOfSymfony / FOSUserBundle

Provides user management for your Symfony project. Compatible with Doctrine ORM & ODM, and custom storages.
https://symfony.com/doc/master/bundles/FOSUserBundle/index.html
MIT License
3.25k stars 1.58k forks source link

Extending the extended User Class #1166

Open Fraktl opened 11 years ago

Fraktl commented 11 years ago

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)

stof commented 11 years ago

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)

Fraktl commented 11 years ago

@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.

hugohenrique commented 11 years ago

May I suggest as I used .. the system that I'm developing now I have 3 user types.

  1. Provider      1.1 Personal      1.2 Corporate
  2. 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.

sstok commented 11 years ago

@stof does that include JOINED Table inheritance?

stof commented 11 years ago

@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.

sstok commented 11 years ago

I was actually talking about the performance impact ;) how much slower is it actually?

stof commented 11 years ago

@sstok it forbids using lazy-loading in any place where you have a ToOne relation with the user as target

Fabuloops commented 6 years ago

@sstok Is it still inadvisable to inherit the BaseUser class? Or has it changed since 2013?

sstok commented 6 years ago

@Fabuloops I am not using the FosUserBundle anymore, so I don't know :)