From 3daaf9886a2212ce61b871daf37463cb0ce88c59 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 13 Apr 2017 11:44:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E6=A8=A1=E5=9E=8B=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E7=9B=B4=E6=8E=A5=E7=BC=93=E5=AD=98=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 17 ++++++----------- library/traits/model/SoftDelete.php | 2 +- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 08b967df..50d3ce5a 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -32,7 +32,7 @@ use think\model\relation\MorphTo; */ abstract class Model implements \JsonSerializable, \ArrayAccess { - // 数据库对象池 + // 数据库查询对象池 protected static $links = []; // 数据库配置 protected $connection = []; @@ -40,7 +40,6 @@ abstract class Model implements \JsonSerializable, \ArrayAccess protected $parent; // 数据库查询对象 protected $query; - protected $queryObj; // 当前模型名称 protected $name; // 数据表名称 @@ -199,18 +198,14 @@ abstract class Model implements \JsonSerializable, \ArrayAccess */ public function getQuery($buildNewQuery = false) { - if (!$buildNewQuery && $this->queryObj) { - return $this->queryObj; - } else { + if ($buildNewQuery) { + return $this->buildQuery(); + } elseif (!isset(self::$links[$this->class])) { // 创建模型查询对象 - $query = $this->buildQuery(); - - if (!$buildNewQuery) { - $this->queryObj = $query; - } + self::$links[$this->class] = $this->buildQuery(); } - return $query; + return self::$links[$this->class]; } /** diff --git a/library/traits/model/SoftDelete.php b/library/traits/model/SoftDelete.php index a5dc9b90..6b2213ac 100644 --- a/library/traits/model/SoftDelete.php +++ b/library/traits/model/SoftDelete.php @@ -143,7 +143,7 @@ trait SoftDelete */ protected function getDeleteTimeField($read = false) { - $field = isset($this->deleteTime) ? $this->deleteTime : 'delete_time'; + $field = property_exists($this, 'deleteTime') && isset($this->deleteTime) ? $this->deleteTime : 'delete_time'; if (!strpos($field, '.')) { $field = '__TABLE__.' . $field; }