I am trying to create a relationship between three models. My models are Roles, Responsibilities, and Employees. Conceptually, I believe i would set the relationships up like this:
Employee table:
id:int Pk
fName: varChar
lName: varChar
Role Table:
roldId: int pk
roleName: varChar
Responsibility Table:
reponsibilityId: PK int
responsibilityName: varChar
role_responsbility table:
role_responsibility_id: PK int
roleId: int FK
responsibilityId int FK
employee_role_responsibility Table:
id: int PK
role_responsibility_id int FK
employee_id: int FK
So, my question is, how do I model these relationships in my CakePHP model? This is what i have so far:
App::uses('AppModel', 'Model');
class Employee extends AppModel {
public $name = "Employee";
}
App::uses('AppModel', 'Model');
class Role extends AppModel {
public $name = "Role";
public $hasAndBelongsToMany = array(
'MemberOf' => array(
'className' => 'Responsibility',
)
);
}
App::uses('AppModel', 'Model');
class Responsibility extends AppModel {
public $name = "Responsibility";
public $hasAndBelongsToMany = array(
'MemberOf' => array(
'className' => 'Role',
)
);
}
How do I join the roles_responsbility table with the employee table?
Thanks