From c9aa1277aafdbc175c7c6a94154e4d8299a264f2 Mon Sep 17 00:00:00 2001 From: Abdul Rahman Reza Date: Thu, 5 Dec 2024 16:34:40 +0900 Subject: [PATCH] update join --- src/controllers/user_activity.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/controllers/user_activity.ts b/src/controllers/user_activity.ts index f3effca..9d6e8dd 100644 --- a/src/controllers/user_activity.ts +++ b/src/controllers/user_activity.ts @@ -5,7 +5,7 @@ import { OrmHelper } from "../helpers/orm"; import Joi from "joi"; import { ILogObj, Logger } from "tslog"; import { Language } from "../langs/lang"; -import { Paging } from "entity"; +import { Paging, User } from "entity"; import CommonHelper from "../helpers/common"; import { ActivityType } from "entity"; import * as fastcsv from 'fast-csv'; @@ -96,11 +96,12 @@ export class UserActivityController { } const res_count = userRepository.createQueryBuilder() - .addSelect('(SELECT u.username FROM users u WHERE u.id = id_user)', 'username') - .having(whereAttr, whereVal); + .leftJoinAndMapOne('u.username', User, 'u', 'u.id = id_user') + .where(whereAttr, whereVal); const res_list = userRepository.createQueryBuilder() - .addSelect('(SELECT u.username FROM users u WHERE u.id = id_user)', 'username') - .having(whereAttr, whereVal) + // .addSelect('(SELECT u.username FROM users u WHERE u.id = id_user)', 'username') + .leftJoinAndMapOne('u.username', User, 'u', 'u.id = id_user') + .where(whereAttr, whereVal) .orderBy(param.order_field, param.order_direction) .offset(offset) .limit(param.limit);