mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-06 15:02:47 +08:00
增加关联延迟预载入(仅针对数据集对象)
This commit is contained in:
@@ -16,6 +16,7 @@ use ArrayIterator;
|
|||||||
use Countable;
|
use Countable;
|
||||||
use IteratorAggregate;
|
use IteratorAggregate;
|
||||||
use JsonSerializable;
|
use JsonSerializable;
|
||||||
|
use think\Model;
|
||||||
|
|
||||||
class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSerializable
|
class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSerializable
|
||||||
{
|
{
|
||||||
@@ -352,6 +353,21 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
|
|||||||
return json_encode($this->toArray(), $options);
|
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()
|
public function __toString()
|
||||||
{
|
{
|
||||||
return $this->toJson();
|
return $this->toJson();
|
||||||
|
|||||||
Reference in New Issue
Block a user