diff --git a/src/model/concern/Conversion.php b/src/model/concern/Conversion.php index a47bbf22..cdfcb86c 100644 --- a/src/model/concern/Conversion.php +++ b/src/model/concern/Conversion.php @@ -264,7 +264,7 @@ public function toArray(): array $val->hidden($hidden[$key], true); } // 关联模型对象 - if (!isset($hidden[$key]) || true !== $hidden[$key]) { + if (array_key_exists($key,$this->with) && (!isset($hidden[$key]) || true !== $hidden[$key])) { $item[$key] = $val->toArray(); } } elseif (isset($visible[$key])) { diff --git a/src/model/concern/RelationShip.php b/src/model/concern/RelationShip.php index 738d0443..6d63e7d4 100644 --- a/src/model/concern/RelationShip.php +++ b/src/model/concern/RelationShip.php @@ -51,6 +51,13 @@ trait RelationShip */ private $relation = []; + /** + * 预载入关联模型 + * + * @var array + */ + protected $with = []; + /** * 关联写入定义信息. * @@ -347,6 +354,8 @@ public function eagerlyResult(array $relations, array $withRelationAttr = [], bo } $relationResult->eagerlyResult($this, $relationName, $subRelation, $closure, $relationCache, $join); + + $this->with[$relationName] = true; } }