我有3张桌子:
colleges (id, name)
departments (id, name, college_id)
students (id, name, college_id, department_id)
以及以下协会:
colleges hasMany departments
departments hasMany students
students belongsTo departments
问题在于,当我尝试一次为所有这些表保存数据时,数据已成功保存,但外键college_id
未保存在students
表中。除此之外,一切都很好。
在college_id
表中获得了departments
,在department_id
表中获得了student
,但未在college_id
表中获得student
编辑: - 贝娄是阵列结构,我正在采取行动
name => 'KITT',
departments => [
0 => [
name => 'ETC'
students => [
0 => [
name => 'Bikash'
],
1 => [
name => 'Nancy'
]
]
],
1 => [
name => 'CSE'
students => [
0 => [
name => 'Czy'
],
1 => [
name => 'ABY'
]
]
]
我的保存代码是
$entity = $this->Colleges->newEntity($this->request->data, [
'associated' => ['Departments.Students']
]);
$this->Colleges->save($entity, ['associated' =>'Departments.Students'])