diff --git a/doc/components/orm/relation/index.md b/doc/components/orm/relation/index.md index fece0cdcea0d7724219a4d731edca3979a42b8c3..0255f67b4832566b68034f6533ca8756177b4b79 100644 --- a/doc/components/orm/relation/index.md +++ b/doc/components/orm/relation/index.md @@ -244,4 +244,10 @@ $model->queryRelations('属性名1', '属性名2'); // 查询后可以这么获取结果 $data = $model->属性名; -``` \ No newline at end of file +``` + +### 为一个列表查询指定关联 + +```php +\Imi\Model\Model::queryRelationsList($modelList); +``` diff --git a/src/Model/Model.php b/src/Model/Model.php index f77cb933725f352d21e94c19f04b40ca1ed7537c..4779aa9f27431d9f9ea261244965bb0d83c6eb53 100644 --- a/src/Model/Model.php +++ b/src/Model/Model.php @@ -530,6 +530,24 @@ abstract class Model extends BaseModel } } + /** + * 为一个列表查询指定关联. + * + * @param array $list + * @param string ...$names + * + * @return array + */ + public static function queryRelationsList(array $list, string ...$names): array + { + foreach ($list as $row) + { + $row->queryRelations(...$names); + } + + return $list; + } + /** * 初始化关联属性. *