改进Model类db方法

This commit is contained in:
thinkphp
2016-12-13 17:42:54 +08:00
parent 5c1c1d5f60
commit 59abc17750

View File

@@ -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);