【问题标题】:How to query against junction table directly如何直接查询联结表
【发布时间】:2022-02-10 06:01:48
【问题描述】:

让我们使用 TypeORM 文档中的多对多表示例:

@ManyToMany(type => Category)
@JoinTable({
    name: "question_categories", // table name for the junction table of this relation
    joinColumn: {
        name: "question",
        referencedColumnName: "id"
    },
    inverseJoinColumn: {
        name: "category",
        referencedColumnName: "id"
    }
})
categories: Category[];

假设我想直接查询此表以运行类似select * from question_categories where category = 3; 的内容。如何使用 TypeORM 的查询构建器来表达这一点?该表与实体不对应,因此我不知道如何使用查询生成器 API 来引用它。我需要为此使用 entityManager.query 吗?

【问题讨论】:

    标签: typeorm


    【解决方案1】:

    我最终为联结表创建了一个新实体,并以这种方式直接查询它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-22
      • 2014-02-15
      • 1970-01-01
      • 2021-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-22
      相关资源
      最近更新 更多