多级关联,不保存父表id

时间:2017-11-16 12:29:38

标签: cakephp orm associations cakephp-3.0

我有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'])

0 个答案:

没有答案