我正在尝试在三个模型之间建立关系。我的模型是角色、职责和员工。从概念上讲,我相信我会这样建立关系:
员工表:
id:int PK
fName: varChar
lName: varChar
角色表:
roldId:int pk
角色名称:varChar
责任表:
reponsibilityId:PK int
责任名称:varChar
角色职责表:
role_responsibility_id:PK 整数
角色 ID:int FK
责任Id int FK
employee_role_responsibility 表:
id:int PK
role_responsibility_id int FK
employee_id:int FK
所以,我的问题是,如何在我的 CakePHP 模型中建模这些关系?这是我到目前为止所拥有的:
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',
)
);
}
如何将 roles_responsbility 表与员工表连接起来?
谢谢