From 84a832b3ec6d6edfe56e17e62a52fc548adcd5cd Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 14 Jan 2017 10:46:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=85=B3=E8=81=94=E5=BB=B6?= =?UTF-8?q?=E8=BF=9F=E9=A2=84=E8=BD=BD=E5=85=A5=EF=BC=88=E4=BB=85=E9=92=88?= =?UTF-8?q?=E5=AF=B9=E6=95=B0=E6=8D=AE=E9=9B=86=E5=AF=B9=E8=B1=A1=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Collection.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/library/think/Collection.php b/library/think/Collection.php index 41b42759..0e718616 100644 --- a/library/think/Collection.php +++ b/library/think/Collection.php @@ -16,6 +16,7 @@ use ArrayIterator; use Countable; use IteratorAggregate; use JsonSerializable; +use think\Model; class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSerializable { @@ -352,6 +353,21 @@ 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();