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();