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; }