mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
独立出think\model\Collection类 用于模型数据集
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
32
library/think/model/Collection.php
Normal file
32
library/think/model/Collection.php
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user