Select attributes on repository.find() with relations (TypeORM)
It's bit late but for all others who visit this page may be helpful
there is a option available in typeorm
so we can get the result how we want.
return this.repository.find({
relations: ['user'],
loadRelationIds: true,
where: { ... },
order: { ... }
});
You can use querybuilder which is one of the most powerful tool of TypeOrm, to do so.
const values = this.billRepository.createQueryBuilder("bill")
.leftJoinAndSelect("bill.user", "user")
.where("bill.accountBill LIKE :accountBill", {accountBill})
.andWhere("user.id = :userId", {userId: user.id})
.select(["user.name", "user.surname"])
.execute();
// NOTE
// .execute() will return raw results.
// To return objects, use .getMany()