改进Model类的save方法 修正Merge类的save方法支持 where参数更新

This commit is contained in:
thinkphp
2016-06-17 11:55:52 +08:00
parent f8d7bb61c8
commit dcc1f7b15e
2 changed files with 17 additions and 7 deletions

View File

@@ -183,10 +183,21 @@ class Merge extends Model
return false;
}
if (empty($where) && !empty($this->updateWhere)) {
$where = $this->updateWhere;
}
if (!empty($where)) {
$pk = $this->getPk();
if (is_string($pk) && isset($data[$pk])) {
unset($data[$pk]);
}
}
// 处理模型数据
$data = $this->parseData($this->name, $this->data);
// 写入主表数据
$result = $db->strict(false)->update($data);
$result = $db->strict(false)->where($where)->update($data);
// 写入附表数据
foreach (static::$relationModel as $key => $model) {