使用 TYPEORM 进行多重连接

Multiple JOIN with TYPEORM

我是 typeorm 的新手,也许有人可以解决我的问题。
我有一些查询,例如:

SELECT t1.id,t2.id_2,t3.event,t3.column1,t4.column1 FROM table1 t1
INNER JOIN table2 t2 ON t1.id = t2.id
INNER JOIN table3 t3 ON t2.event = t3.event
INNER JOIN table4 t4 ON t4.id = t2.id_2 WHERE t3.event = 2019

如何将此查询转换为 typeorm

让我们一一分解,好吗? 假设你知道如何那么它会很简单:

await getManager()
        .createQueryBuilder(table1, 't1')
        .select('t1.id', 't1_id')
        .addSelect('t2.id_2', 't2_id_2')
        .addSelect('t3.event', 't3_event')
        .addSelect('t4.column1', 't4_column1') // up to this point: SELECT t1.id,t2.id_2,t3.event,t3.column1,t4.column1 FROM table1 t1
        .innerJoin(table2, 't2', 't1.id = t2.id') //INNER JOIN table2 t2 ON t1.id = t2.id
        .innerJoin(table3, 't3', 't2.event = t3.event') // INNER JOIN table3 t3 ON t2.event = t3.event
        .innerJoin(table4, 't4', 't4.id = t2.id_2') // INNER JOIN table4 t4 ON t4.id = t2.id_2 
        .where('t3.event = 2019') // WHERE t3.event = 2019
        .getRawMany() // depend on what you need really

你可以参考这个来检查你想要什么样的输出:https://github.com/typeorm/typeorm/blob/master/docs/select-query-builder.md#getting-values-using-querybuilder

无论您希望数据作为实体(getOnegetMany)还是它是什么(getRawOnegetRawMany