独立出think\model\Collection类 用于模型数据集

This commit is contained in:
thinkphp
2017-01-16 11:16:15 +08:00
parent f49ebcdc1d
commit f923c9dba5
3 changed files with 33 additions and 15 deletions

View File

@@ -352,21 +352,6 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
return json_encode($this->toArray(), $options);
}
/**
* 延迟预载入关联查询
* @access public
* @param mixed $relation 关联
* @return $this
*/
public function load($relation)
{
$item = current($this->items);
if ($item instanceof Model) {
$item->eagerlyResultSet($this->items, $relation);
}
return $this;
}
public function __toString()
{
return $this->toJson();

View File

@@ -14,6 +14,7 @@ namespace think;
use InvalidArgumentException;
use think\db\Query;
use think\Exception\ValidateException;
use think\model\Collection;
use think\model\Relation;
use think\model\relation\BelongsTo;
use think\model\relation\BelongsToMany;

View File

@@ -0,0 +1,32 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: zhangyajun <448901948@qq.com>
// +----------------------------------------------------------------------
namespace think\model;
use think\Collection as BaseCollection;
class Collection extends BaseCollection
{
/**
* 延迟预载入关联查询
* @access public
* @param mixed $relation 关联
* @return $this
*/
public function load($relation)
{
$item = current($this->items);
if ($item instanceof Model) {
$item->eagerlyResultSet($this->items, $relation);
}
return $this;
}
}