如何直接查询联结 table

How to query against junction table directly

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

@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[];

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

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