Browse Source

feat(category): 添加文章分类关联文章功能

- 在 ArticleCategory 模型中新增 article 关联方法
- 修改 ArticleCategoryService 中 getList 方法,增加预加载 article 关系
- 支持在获取分类列表时同时获取关联的文章数据
master
zhangf@suq.cn 5 days ago
parent
commit
7e95ab9d2b
  1. 4
      app/model/ArticleCategory.php
  2. 2
      app/service/ArticleCategoryService.php

4
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');
}
}

2
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');
}

Loading…
Cancel
Save