1.模块下的model是手动指定$table
2.公共common.php非模块里 有用db()函数用默认的databa
在第一次使用该模块下的模型时 think\Model 下的buildQuery $this->connection 应该是空,走不进配置
    /**
     * 创建模型的查询对象
     * @access protected
     * @return Query
     */
    protected function buildQuery()
    {
        // 合并数据库配置
        if (!empty($this->connection)) {
            if (is_array($this->connection)) {
                $connection = array_merge(Config::get('database'), $this->connection);
            } else {
                $connection = $this->connection;
            }
        } else {
            $connection = [];
        }
        $con = Db::connect($connection);
        // 设置当前模型 确保查询返回模型对象
        $queryClass = $this->query ?: $con->getConfig('query');
        $query      = new $queryClass($con, $this->class);
        // 设置当前数据表和模型名
        if (!empty($this->table)) {
            $query->setTable($this->table);
        } else {
            $query->name($this->name);
        }
        if (!empty($this->pk)) {
            $query->pk($this->pk);
        }
        return $query;
    }/**
     * 数据库初始化 并取得数据库类实例
     * @static
     * @access public
     * @param mixed         $config 连接配置
     * @param bool|string   $name 连接标识 true 强制重新连接
     * @return Connection
     * @throws Exception
     */
    public static function connect($config = [], $name = false)
    {
        if (false === $name) {
            $name = md5(serialize($config));
        }
        if (true === $name || !isset(self::$instance[$name])) {
            // 解析连接参数 支持数组和字符串
            $options = self::parseConfig($config);
            if (empty($options['type'])) {
                throw new \InvalidArgumentException('Undefined db type');
            }
            $class = false !== strpos($options['type'], '\\') ? $options['type'] : '\\think\\db\\connector\\' . ucwords($options['type']);
            // 记录初始化信息
            if (App::$debug) {
                Log::record('[ DB ] INIT ' . $options['type'], 'info');
            }
            if (true === $name) {
                $name = md5(serialize($config));
            }
            self::$instance[$name] = new $class($options);
        }
        return self::$instance[$name];
    }$con = Db::connect($connection);这里的 $connection是个空数组,传进去会直接return self::$instance[$name];
不知是不是我哪里错了,还是确实是BUG
最佳答案
		