diff --git a/library/think/Collection.php b/library/think/Collection.php index 7b57ee03..41b42759 100644 --- a/library/think/Collection.php +++ b/library/think/Collection.php @@ -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(); diff --git a/library/think/Model.php b/library/think/Model.php index 14deb300..1e1d4460 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -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; diff --git a/library/think/model/Collection.php b/library/think/model/Collection.php new file mode 100644 index 00000000..81ca17a9 --- /dev/null +++ b/library/think/model/Collection.php @@ -0,0 +1,32 @@ + +// +---------------------------------------------------------------------- + +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; + } +}