我的“PatientCase”模型与“PatientCaseOrder”模型具有 hasOne 关系。(该表仅存储了 patientCase id 以及一个整数位置)
我正在使用 ajax 函数在我的 PatientCase 控制器中使用以下函数更新“PatientCaseOrder”中的位置字段
public function update_position(){
Configure::write('debug', 0);
$this->autoRender = false;
$this->loadModel('PatientCaseOrder');
$list = $_POST['list'];
$errs = false;
if($list){
foreach($list as $position){
$id = $position[0];
$pos = $position[1];
$this->PatientCase->id = $id;
if(! $this->PatientCase->PatientCaseOrder->saveField('position', $pos))
$errs = true;
}
}
echo json_encode ($errs);
}
我正在向它传递一个包含 PatientCaseId 和位置的数组。该代码产生 500 服务器错误,我哪里出错了,或者我采取了错误的方法?
注意:我之前在 PatientCase 模型中有 position 字段,这行代码与上面的代码段一起使用
$this->PatientCase->saveField('position', $pos)