// 检测提交字段的合法性
if(isset($this->options['field'])) { // $this->field('field1,field2...')->create()
$fields = $this->options['field'];
unset($this->options['field']);
}elseif($type == self::MODEL_INSERT && isset($this->insertFields)) {
$fields = $this->insertFields;
}elseif($type == self::MODEL_UPDATE && isset($this->updateFields)) {
$fields = $this->updateFields;
//zll
if (is_string($fields)) {
$fields = explode(',', $fields);
}
$pk = $this->getPk();
if (is_string($pk)) {
array_push($fields, $pk);
}
if (is_array($pk)) {
foreach ($pk as $pkTemp) {
array_push($fields, $pkTemp);
}
}
//zll
}
Model的create方法中检测提交字段的合法性,如果表单数据中有主键或者指定type=2,会判定为更新操作,从而执行一下代码:
elseif($type == self::MODEL_UPDATE && isset($this->updateFields)) {
$fields = $this->updateFields;
然后$fields中会不包含主键或者复合主键属性。从而导致save方法调用时的$data中不包含主键或者复合主键属性,保存失败。
虽然可以在Model的$updateFields中加入主键或者复合主键,但是这明显是和$updateFields的含义相违背的。