0
我有以下功能:CakePHP的3.3.0不更新hasOne表
public function edit($id = null)
{
$resident = $this->Residents->get($id, [
'contain' => [ 'ResidentGeneral' ]
]);
if ($this->request->is(['patch', 'post', 'put'])) {
$resident = $this->Residents->patchEntity($resident, $this->request->data);
if ($this->Residents->save($resident)) {
$this->Flash->success(__('The resident has been saved.'));
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('The resident could not be saved. Please, try again.'));
}
}
$titles = $this->Residents->ResidentGeneral->Titles->find('list', ['limit' => 200]);
$sexes = $this->Residents->ResidentGeneral->Sexes->find('list', ['limit' => 200]);
$maritalStatuses = $this->Residents->ResidentGeneral->MaritalStatuses->find('list', ['limit' => 200]);
$rooms = $this->Residents->ResidentGeneral->Rooms->find('list', ['limit' => 200]);
$nationalities = $this->Residents->ResidentGeneral->Nationalities->find('list', ['limit' => 200]);
$ethnicOrigins = $this->Residents->ResidentGeneral->EthnicOrigins->find('list', ['limit' => 200]);
$this->set(compact('resident', 'titles', 'sexes', 'maritalStatuses', 'rooms', 'nationalities', 'ethnicOrigins'));
$this->set('_serialize', ['resident']);
}
ADD功能是具有
$resident = $this->Residents->get($id, [
'contain' => [ 'ResidentGeneral' ]
]);
是代替
$resident = $this->Residents->newEntity();
和异常相同$ id = null从顶部丢失。
现在,add函数将正确地保存到数据库,并为居民提供一个问题的常规表格,但编辑不会更新,它们使用相同的表格,因此所有约定都被保留。
关于此的文档指出,修补程序和保存都与关联一起工作一层,即使如此添加也不工作,也因为添加功能工作,这意味着所有模型都可以正常工作,但是这将不会更新表中的任何关联记录。
正如您可能看到大部分代码已经过烘焙,所以这是框架的运行方式。
任何帮助都会很棒,因为我离破碎的电脑只有一步之遥。
我有节能问题协会(belongsToMany)也在3.3,回到了3.2.14和它的工作。我不知道为什么,相同的代码。 –
我在另一个开发人员的电脑上发现了相同的情况,他可以使用3.2.X进行编辑,但不能使用3.3.X,核心有可能出现问题吗? – B1scuit
刚试过一个全新的安装,两个表和一个hasOne之间,同样的事情,没有更新的内容,会引发github上的问题 – B1scuit