我的方法返回一个包含所有 User 对象的 bill 对象。我希望我只返回实体中具有两个属性的账单对象和用户。我使用 TypeORM
/**
* Returns a bills by account bill
*/
async getByAccountBill(
accountBill: string,
id?: number
): Promise<Object | undefined> {
const userService = new UserService();
const user = await userService.getById(id);
const bills = await this.billRepository.find({
select: ["accountBill"],
where: {
accountBill: Like(`${accountBill}%`),
user: Not(`${user.id}`)
},
relations: ["user"] // I get All object Entity (userId, password, login...) I want to only name and surname
});
if (bills) {
return bills;
} else {
return undefined;
}
}
原文由 promiseREact5 发布,翻译遵循 CC BY-SA 4.0 许可协议
您可以使用 TypeOrm 最强大的工具之一查询生成器来执行此操作。