From e40962c346de9602798b224ef9304d5ddfed3e0d Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 10 Mar 2017 11:14:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3Model=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 | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 8471ac8e..d3c4d837 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -779,19 +779,19 @@ abstract class Model implements \JsonSerializable, \ArrayAccess return false; } - protected function autoWriteUpdateTime() + protected function autoWriteUpdateTime(&$data) { // 自动写入更新时间 if ($this->autoWriteTimestamp && $this->updateTime && (empty($this->change) || !in_array($this->updateTime, $this->change))) { - $this->setAttr($this->updateTime, null); + $data[$this->updateTime] = $this->autoWriteTimestamp($this->updateTime); } } - protected function autoWriteCreateTime() + protected function autoWriteCreateTime(&$data) { // 自动写入创建时间 if ($this->autoWriteTimestamp && $this->createTime && (empty($this->change) || !in_array($this->createTime, $this->change))) { - $this->setAttr($this->createTime, null); + $data[$this->createTime] = $this->autoWriteTimestamp($this->createTime); } } @@ -887,7 +887,8 @@ abstract class Model implements \JsonSerializable, \ArrayAccess } if (!empty($data)) { - $this->autoWriteUpdateTime(); + // 自动写入更新时间 + $this->autoWriteUpdateTime($data); } else { return 0; } @@ -938,9 +939,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess } else { // 自动写入 $this->autoCompleteData($this->insert); - - $this->autoWriteCreateTime(); - $this->autoWriteUpdateTime(); + // 自动写入创建时间 + $this->autoWriteCreateTime($this->data); + // 自动写入更新时间 + $this->autoWriteUpdateTime($this->data); if (false === $this->trigger('before_insert', $this)) { return false;