From 7e95ab9d2b2f658e21d019a02580707c2db1eb73 Mon Sep 17 00:00:00 2001 From: "zhangf@suq.cn" Date: Fri, 12 Dec 2025 11:29:16 +0800 Subject: [PATCH] =?UTF-8?q?feat(category):=20=E6=B7=BB=E5=8A=A0=E6=96=87?= =?UTF-8?q?=E7=AB=A0=E5=88=86=E7=B1=BB=E5=85=B3=E8=81=94=E6=96=87=E7=AB=A0?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 ArticleCategory 模型中新增 article 关联方法 - 修改 ArticleCategoryService 中 getList 方法,增加预加载 article 关系 - 支持在获取分类列表时同时获取关联的文章数据 --- app/model/ArticleCategory.php | 4 ++++ app/service/ArticleCategoryService.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/model/ArticleCategory.php b/app/model/ArticleCategory.php index 194879b..51cc6c4 100644 --- a/app/model/ArticleCategory.php +++ b/app/model/ArticleCategory.php @@ -30,4 +30,8 @@ class ArticleCategory extends BaseModel */ public $timestamps = true; + public function article() + { + return $this->hasMany(CreationArticle::class, 'article_category_id', 'id'); + } } \ No newline at end of file diff --git a/app/service/ArticleCategoryService.php b/app/service/ArticleCategoryService.php index 5a0b0ec..b348270 100644 --- a/app/service/ArticleCategoryService.php +++ b/app/service/ArticleCategoryService.php @@ -76,7 +76,7 @@ class ArticleCategoryService extends BaseService if (isNotBlank($params['end_time'])) { $query[] = ['create_time', '<=', strtotime($params['end_time'] . ' 23:59:59')]; } - $list = $this->dao->getList($query, '*', $page, $limit, "$sortField $sortRule"); + $list = $this->dao->getList($query, '*', $page, $limit, "$sortField $sortRule", [], ['article']); $count = $this->dao->getCount($query); return compact('list', 'count'); }