I'm building an application using the Auth module for which I need at least 3 account types : Employer, Employee and Client. Since these accounts have different properties, functions and relationships (ex: employers has_many employees) I guess I need to have them on 3 separate ORM models.
The method I thought was to tweak the Auth module to replace the 'User' model with the appropriate sub-model (employer, employee, client), corresponding the the user type in the database.
Can this be done, or is it bad practice?
For such rurposes you need to create different Model classes for each account type extending default Auth_ORM's Model_User
class.
Then you need to create new Auth_ORM
class extending Kohana_Auth_ORM
class in your application/classes
folder.
In this file you need to rewrite protected _login()
method, so its $user
variable to point to required account type.
I have found interesting repository here: https://github.com/alexgisby/MAuth.
I have the same problem as You have, so maybe if You manage to resolve it You could share the solution. I think the repository from this link could be a solution, but i didn't manage to implement it so far
You can have 1 model - User and 3 different roles. And depending to role, you can load specific module, which will contain required classes.
For example, if User has role Employee you will load modules/role_employee