From a05397b341fe0c96edd2f80d59654f71da290b0d Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 7 Apr 2017 19:02:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3Connection=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 2 +- library/think/db/Connection.php | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index ee8b5b9f..ae6c27d7 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -175,7 +175,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess // 设置当前模型 确保查询返回模型对象 $queryClass = $this->query ?: $con->getConfig('query'); $query = new $queryClass($con, $this->class); - $con->setQuery($query); + $con->setQuery($query, $this->class); // 设置当前数据表和模型名 if (!empty($this->table)) { diff --git a/library/think/db/Connection.php b/library/think/db/Connection.php index ab9a4adf..eba58229 100644 --- a/library/think/db/Connection.php +++ b/library/think/db/Connection.php @@ -57,7 +57,7 @@ abstract class Connection // 监听回调 protected static $event = []; // 查询对象 - protected $query; + protected $query = []; // 使用Builder类 protected $builder; // 数据库连接参数配置 @@ -142,9 +142,9 @@ abstract class Connection * @param Query $query 查询对象 * @return $this */ - public function setQuery($query) + public function setQuery($query, $model = 'db') { - $this->query = $query; + $this->query[$model] = $query; return $this; } @@ -154,15 +154,15 @@ abstract class Connection * @access public * @return Query */ - public function getQuery() + public function getQuery($model = 'db') { - if (!isset($this->query)) { + if (!isset($this->query[$model])) { $class = $this->config['query']; - $this->query = new $class($this); + $this->query[$model] = new $class($this, 'db' == $model ? '' : $model); } - return $this->query; + return $this->query[$model]; } /**