From 9ac6e9e3fdbc4759ab6526b0cf0998727559afda Mon Sep 17 00:00:00 2001 From: ItsMalma Date: Fri, 12 Dec 2025 12:33:17 +0700 Subject: [PATCH] fix article populate --- src/modules/article/article.controller.ts | 29 +++++++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/modules/article/article.controller.ts b/src/modules/article/article.controller.ts index 8b04dca..b860e5a 100644 --- a/src/modules/article/article.controller.ts +++ b/src/modules/article/article.controller.ts @@ -56,9 +56,15 @@ export class ArticleController extends Controller { }); for (const [index, tagId] of body.tag_ids.entries()) { - const tag = await orm.em.findOne(Tag, { - id: tagId, - }); + const tag = await orm.em.findOne( + Tag, + { + id: tagId, + }, + { + populate: ["*"], + }, + ); if (!tag) { return res.status(404).json({ data: null, @@ -101,6 +107,7 @@ export class ArticleController extends Controller { limit: query.per_page, offset: (query.page - 1) * query.per_page, orderBy: { createdAt: "DESC" }, + populate: ["*"], }); return res.status(200).json({ @@ -122,7 +129,13 @@ export class ArticleController extends Controller { } const params = parseParamsResult.data; - const article = await orm.em.findOne(Article, { slug: params.slug }); + const article = await orm.em.findOne( + Article, + { slug: params.slug }, + { + populate: ["*"], + }, + ); if (!article) { return res.status(404).json({ data: null, @@ -159,7 +172,13 @@ export class ArticleController extends Controller { } const body = parseBodyResult.data; - const article = await orm.em.findOne(Article, { slug: params.slug }); + const article = await orm.em.findOne( + Article, + { slug: params.slug }, + { + populate: ["*"], + }, + ); if (!article) { return res.status(404).json({ data: null,