小编pro*_*ct5的帖子

在 repository.find() 上选择具有关系的属性(TypeORM)

我的方法返回一个包含所有用户对象的账单对象。我希望我只返回实体中具有两个属性的账单对象和用户。我使用 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;
    }
  }
Run Code Online (Sandbox Code Playgroud)

javascript typescript typeorm

15
推荐指数
2
解决办法
3万
查看次数

标签 统计

javascript ×1

typeorm ×1

typescript ×1