From 9b353811af24921322f5bccb4e03617cbda6f8d7 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 17 Apr 2017 12:35:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9Bmodel=E7=B1=BBsave=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/library/think/Model.php b/library/think/Model.php index 079df3b1..f2acbad5 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -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])) { // 自动写入更新时间