数据库配置信息增加query参数用于配置查询对象名称 模型类增加query属性用于配置模型需要的查询对象名称

This commit is contained in:
thinkphp
2016-09-20 12:04:09 +08:00
parent c1a2db30c7
commit 35890dad5c
2 changed files with 11 additions and 5 deletions

View File

@@ -39,11 +39,12 @@ use think\paginator\Collection as PaginatorCollection;
*/
abstract class Model implements \JsonSerializable, \ArrayAccess
{
// 数据库对象池
protected static $links = [];
// 数据库配置
protected $connection = [];
// 数据库查询对象
protected $query;
// 当前模型名称
protected $name;
// 数据表名称
@@ -147,7 +148,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
$model = $this->class;
if (!isset(self::$links[$model])) {
// 设置当前模型 确保查询返回模型对象
$query = Db::connect($this->connection)->model($model);
$query = Db::connect($this->connection)->model($model, $this->query);
// 设置当前数据表和模型名
if (!empty($this->table)) {