From f3ff63268ad3a59940dca6987d1729ffd088ad18 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 16 Aug 2016 22:39:53 +0800 Subject: [PATCH] =?UTF-8?q?Model=E7=B1=BBget=E6=96=B9=E6=B3=95=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E4=B8=BB=E9=94=AE=E6=9F=A5=E8=AF=A2=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 3 +++ library/think/db/Query.php | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/library/think/Model.php b/library/think/Model.php index cb7bd21f..e4306697 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -985,6 +985,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess */ public static function get($data = null, $with = [], $cache = false) { + if (!$cache && $data && is_scalar($data)) { + $cache = true; + } $query = static::parseQuery($data, $with, $cache); return $query->find($data); } diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 3a687f13..a3e8ac2e 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1768,8 +1768,8 @@ class Query public function update(array $data) { $options = $this->parseExpress(); + $pk = $this->getPk($options); if (empty($options['where'])) { - $pk = $this->getPk($options); // 如果存在主键数据 则自动作为更新条件 if (is_string($pk) && isset($data[$pk])) { $where[$pk] = $data[$pk]; @@ -1793,6 +1793,8 @@ class Query } else { $options['where']['AND'] = $where; } + } elseif (is_string($pk) && isset($options['where']['AND'][$pk]) && is_scalar($options['where']['AND'][$pk])) { + $key = 'think:' . $options['table'] . '|' . $options['where']['AND'][$pk]; } // 生成UPDATE SQL语句 $sql = $this->builder()->update($data, $options);