Im building a user management system based on 2 pillars.
1. Roles
Each user have multiple roles.
2. Rights
Every role consists of one or more rights.
Users and roles are working fine in my attempt:
class Model_Auth_User extends ORM {
protected $_has_many = array(
'roles' => array('model' => 'Role', 'through' => 'roles_users'),
);...}
class Model_Auth_Role extends ORM {
protected $_has_many = array(
'users' => array('model' => 'User','through' => 'roles_users'),
);...}
I am trying to add some Roles and Rights the same way:
class Model_Auth_Role extends ORM {
protected $_has_many = array(
'users' => array('model' => 'User','through' => 'roles_users'),
'rights' => array('model' => 'Right','through' => 'role_rights'),
);
class Model_Auth_Right extends ORM {
protected $_has_many = array(
'roles' => array('model' => 'Role','through' => 'role_rights'),
);
The access to the roles works fine like this:
$roles = $user->roles->find_all(); //works fine
However, the access to the Rights of a Role always delivers an empty result:
$rights = $user->roles->rights->find_all();
Because $user->roles i collection
<?php
$rights = [];
foreach($user->roles->find_all() as $role){
$rights[] = $role->rights->find_all();
}