CakePHP 3:无法与关联模型一起保存

时间:2015-10-23 20:02:57

标签: cakephp cakephp-3.0

我在控制器中保存了模型数据。现在我需要在保存后获得一些关联模型。

现在模型不会保存。我不想保存关联的模型。我不明白为什么会失败。

$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);
}

0 个答案:

没有答案
相关问题