From 59abc177505e62b9b87474f7126377093f856a86 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 13 Dec 2016 17:42:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BModel=E7=B1=BBdb=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 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index d40c6218..1a9677d4 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -169,10 +169,14 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $model = $this->class; if (!isset(self::$links[$model])) { // 合并数据库配置 - if (is_array($this->connection)) { - $connection = array_merge(Config::get('database'), $this->connection); + if (!empty($this->connection)) { + if (is_array($this->connection)) { + $connection = array_merge(Config::get('database'), $this->connection); + } else { + $connection = $this->connection; + } } else { - $connection = $this->connection; + $connection = []; } // 设置当前模型 确保查询返回模型对象 $query = Db::connect($connection)->model($model, $this->query);