我不知道如何使用MySql查询生成器编写以下TypeOrm语句
从farm.reg中选择grpId = 'ABC';
此选择只返回id,但我的查询生成器将返回整个对象。
在这一刻,我在我的NestJ服务中有了这个函数,但是我需要使用“map”,我不想使用。
async getGrupIds(entity: string, grpId: string) {
console.log(entity, grpId);
const ids = await getRepository(reg)
.createQueryBuilder(entity)
.where('reg.grpId = :grpId', {grpId: grpId})
.getMany();
console.log(ids);
return ids.map(o => o.id);
}谢谢
发布于 2020-04-15 06:46:49
如果要选择实体的某些指定字段,请尝试使用getRawMany()而不是getMany():
//I suppose you have a *grpId* variable in your function
const ids = await getRepository(Reg)
.createQueryBuilder('reg')
.select('reg.grpId', 'id')
.where('reg.grpId = :grpId', { grpId } )
.getRawMany();
console.log(ids);
return ids
}https://stackoverflow.com/questions/61214198
复制相似问题