【问题标题】:using function into typeorm consult在 typeorm 中使用函数
【发布时间】:2021-03-02 19:42:22
【问题描述】:

我有下一个代码:

const CompaniesRelation: Array<CompanyRelation> = await getRepository(CompanyRelation).find({ where:{ UserId: data.UserId, IsActive: true} });

它应该返回一个包含如下对象的数组:

[{CompanyId"a"},{CompanyId"b"},{CompanyId"c"}]

我的下一步是:

const ids: Array<string> = CompaniesRelation.map(c => c.CompanyId);

我需要在 TypeOrm 选择中使用它,在这里我需要选择一个表的所有内容,其中数组等于 COmpany 和 CompaniesRelation 之间的 ID

 const CompanyData: Array<Company> = await getRepository(Company).find({ where:{ CompanyId: data.UserId IN(´${JSON.stringify(ids).slice(1, -1)}´) } });

所以它的语法是错误的,但我不知道为什么,它的正确语法如何以及如何获得我正在尝试的数组?

【问题讨论】:

    标签: typescript typeorm


    【解决方案1】:

    你可以试试:

    const CompanyData: Array<Company> = await getRepository(Company).find({ where:{ CompanyId: In(ids)  } });
    

    In()是typeorm函数

    【讨论】:

      猜你喜欢
      • 2022-10-14
      • 1970-01-01
      • 2021-12-08
      • 1970-01-01
      • 2021-07-20
      • 2020-10-22
      • 2020-07-29
      • 2022-12-18
      • 1970-01-01
      相关资源
      最近更新 更多