我在控制器中保存了模型数据。现在我需要在保存后获得一些关联模型。
现在模型不会保存。我不想保存关联的模型。我不明白为什么会失败。
$this->request->allowMethod('ajax');
$modulesEmployee = $this->ModulesEmployees->get($this->request->data['id'], [
'contain' => ['CourseModules']
]);
$update = $modulesEmployee->toArray();
$update['completed_on'] = date('Y-m-d H:i:s');
$update['completed'] = true;
$modulesEmployee = $this->ModulesEmployees->patchEntity($modulesEmployee, $update);
if ($this->ModulesEmployees->save($modulesEmployee)) {
// Do some work with the associated CourseModules
} else {
$data['response'] = "Error: ModulesEmployees could not be saved";
$this->response->statusCode(400);
}