如何从@ManyToMany获取数据?

时间:2020-07-20 10:44:03

标签: javascript typescript nestjs typeorm relation

我的@ManyToMany中有一个关系UserEntity

  @ManyToMany(
    () => Order,
    orders=> orders.users,
  )
  orders?: Order[];

如何通过一个查询从该表中获取数据?

我试试这个:

        const user = await this.conn
            .getRepository(UserEntity)
            .createQueryBuilder('user')
            .addSelect('firstName')
            .addSelect('lastName')
            .leftJoin('user.order', 'order', 'order.id = user.id')
            .getRawMany();

但是启动后,我的控制台会抛出我:

[Nest] 1262   - 07/20/2020, 12:47:41 PM   [ExceptionsHandler] Column 'id' in field list is ambiguous +1670ms
QueryFailedError: Column 'id' in field list is ambiguous

感谢您的帮助

0 个答案:

没有答案