FOSUserBundle properties in registration form from another entity
Semantically speaking, a User
doesn't have to be a person, so I see no reason for a company being your application's user. I also see no reason for having two separate tables in your database.
I would create a separate Company class, which extends the user class:
namespace Acme\Bundle\AcmeBundle\Entity;use FOS\UserBundle\Entity\User;class Company extends User{ // Your company related fields and related getters/setters go here.}
Then override the user class from your configuration (e.g in app/config/config.yml
):
fos_user: user_class: Acme\Bundle\AcmeBundle\Entity\Company
Now the UserBundle
knows which class to use as the User
. After setting up your custom class you can override the RegistrationFormType
to include your custom fields.
If, however, you still wish to use two separate entities in your application, I suggest you connect them via a One-To-One relationship and then embed your Company
entity to RegistrationFormType
by following the docs about embedding a single object to a form.
Reference: https://github.com/FriendsOfSymfony/FOSUserBundle/blob/1.2.0/Resources/doc/overriding_forms.md