From f923c9dba55c5c358eb9ee8139ed9bb765a378b6 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 16 Jan 2017 11:16:15 +0800 Subject: [PATCH] =?UTF-8?q?=E7=8B=AC=E7=AB=8B=E5=87=BAthink\model\Collecti?= =?UTF-8?q?on=E7=B1=BB=20=E7=94=A8=E4=BA=8E=E6=A8=A1=E5=9E=8B=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Collection.php | 15 -------------- library/think/Model.php | 1 + library/think/model/Collection.php | 32 ++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 15 deletions(-) create mode 100644 library/think/model/Collection.php 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; + } +}