我需要获得兴趣列表及其相关数据,并计算订阅兴趣的客户
我的利益和客户之间有多对一的关系。这是唯一可以做的
const list = await this.interestRepository
.createQueryBuilder('interest')
.leftJoinAndSelect("interest.translations", "translations")
.leftJoinAndSelect("interest.customers", "customers")
.getMany()
结果如下:
list [
Interest {
id: 'YJnu_8bpzMSrFiztDl1zH',
creationDate: 2022-12-19T16:49:55.090Z,
countryCode: 'LTU',
rank: 2,
status: 'active',
translations: [ [InterestTranslation], [InterestTranslation] ],
customers: [ [Customer] ]
},
Interest {
id: '-h1UPpOSkw4TqcTc7F5Ej',
creationDate: 2022-12-19T16:57:47.718Z,
countryCode: 'USA',
rank: 1,
status: 'active',
translations: [ [InterestTranslation], [InterestTranslation] ],
customers: []
}
]
但是我想计数客户,而不是得到所有客户,因为可能有成千上万的客户,这会影响请求的持续时间。
如果我没理解错的话,你需要把这个
.loadRelationCountAndMap('interest.customers', 'interest.customers')
不是
.leftJoinAndSelect("interest.customers", "customers")