Friday, 6 September 2013

Best inheritance strategy for FOS UserBundle?

Best inheritance strategy for FOS UserBundle?

I want to use FOS USerBundle but i have different kind of users(Student,
Teacher, Director, etc) who can login into my application. Each of then
have differents properties uniques for each one.
As i see i have some options:
Option 1-To have a User entity inheriting FOS\UserBundle\Entity\User (and
set in the config.yml as the user_class for FOS UserBundle) with all the
properties for the differents kind of user differenciated by ROLE. I
particularly don't like this option because User entity will have a lot of
properties in null every time a user login in the system(just the
properties for the logged kind of user will have values, the rest of
properties(almost of there) will be unused.
Option 2-To have a User entity inheriting FOS\UserBundle\Entity\User (and
set in the config.yml as the user_class for FOS UserBundle), create one
entity for each actor in the application(Student, Teacher, Director, etc)
with a relation of OneToOne with the User entity. In this way every time a
user login, i will be able to say: $logguedUser->getStudent() or
$logguedUser->getTeacher(), etc, depending the kind of user loggued in.
Option 3-To have a User entity inheriting FOS\UserBundle\Entity\User,
create one entity for each actor in the application(Student, Teacher,
Director, etc) and each of that entities inherits from User. This is the
option i see in theory better, but i can't figurate how to implemet it
since i need to say FOS UserBundle in the configuration witch is
user_class, and i will hace some of then(Student, Client, Director, etc).
When a actor logged in the application, which object i will have logged?
Do anyone have a better option, or a way to implement the third, or maybe
support one? Tx

No comments:

Post a Comment