Search code examples
ormsymfonydoctrine-ormmappingrelationships

Which class i need to use for custom authentication in symfony2


I am totally confused with the object oriented inheritance things

I have this scenario

Class User

Then

Class Employee extends User attributes username, password

then

Class Owners extend User

Each class has different attributes

Now all the login details will be in User table.

But i am confused that suppose

  1. If i use class User for authentication and Employee logs in, then the object i will be having is of type User not employee

  2. How will i get access to the attributes of Employee from that User object. If iclick on edit then how will employee details gets loaded


Solution

  • You need to use some kind of inheritance (single table or multi table, doctrine should return the correct type, even if you query on the normal User entity), and have each object return different roles depending on their type (if you want to limit their access).

    https://github.com/netmeansnet/NmnMultiUserBundle this can proberly be inspirational.