增加关联延迟预载入(仅针对数据集对象)

This commit is contained in:
thinkphp
2017-01-14 10:46:21 +08:00
parent 74a5101c9a
commit 84a832b3ec

View File

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