我在多对多关系中有员工和复合体。我使用烘焙控制台为员工和复合体表生成模型、控制器……。我的问题是:-因为我的 BD 中有“complexes_employees”表,我是否也必须为这个表烘焙模型和控制器,或者 cakePHP 能够知道它包含员工和复合体的两个外键。
第二个问题:-如何将我的数据保存在这三个表中。对于我的应用程序,我必须为每个 Complex 保存员工。
// Employees Controller
public function addEmpPerComplex($id_complex){
$emp = $this->Employees->newEntity();
if ($this->request->is('post')) {
$employee = $this->Employees->patchEntity($employee, $this->request->data, ['associated'=>['Complexes._joinData']] );
//here I need to insert the record that contains the employee data in Employees Table
// then I need to insert in "complexes_employees" the ID of Complex sended in parametre of this function and the ID of the new Employee
谢谢你帮助我