From 198ea76923f4c3b104f35a5f4f27a58208805f9c Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 18 May 2016 10:20:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BQuery=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/Query.php | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 03b52e46..befb147e 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -875,7 +875,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess // 设置当前数据表和模型名 if (!empty($class->table)) { - self::$links[$model]->table($class->table); + self::$links[$model]->setTable($class->table); } else { $name = !empty($class->name) ? $class->name : basename(str_replace('\\', '/', $model)); self::$links[$model]->name($name); diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 3ad257d4..cb6a0f8c 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -786,14 +786,26 @@ class Query } /** - * 指定数据表 + * 指定默认数据表 + * @access public + * @param string $table 表名 + * @return $this + */ + public function setTable($table) + { + $this->table = $table; + return $this; + } + + /** + * 指定当前操作的数据表 * @access public * @param string $table 表名 * @return $this */ public function table($table) { - $this->table = $table; + $this->options['table'] = $table; return $this; }