改进model类save方法

This commit is contained in:
thinkphp
2017-04-17 12:35:28 +08:00
parent 9ea7f48e1a
commit 9b353811af

View File

@@ -941,7 +941,20 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
$data = $this->getChangedData();
if (empty($data) || (count($data) == 1 && is_string($pk) && isset($data[$pk]))) {
// 没有更新
// 关联更新
if (isset($relation)) {
foreach ($relation as $name => $val) {
if ($val instanceof Model) {
$val->save();
} else {
unset($this->data[$name]);
$model = $this->getAttr($name);
if ($model instanceof Model) {
$model->save($val);
}
}
}
}
return 0;
} elseif ($this->autoWriteTimestamp && $this->updateTime && !isset($data[$this->updateTime])) {
// 自动写入更新时间