【问题标题】:Cannot query across many to many relations NestJS无法跨多对多关系查询 NestJS
【发布时间】:2022-01-15 03:53:57
【问题描述】:

我正在尝试更新数据,但出现标题中的错误。我的数据有很多关系,如下所示:

类别实体:

  @ManyToMany(() => Product, (product: Product) => product.categories)

公共产品:Product[];

产品实体:

  @ManyToMany(() => Category, (category: Category) => category.products)

@JoinTable() 公共类别:Category[];

更准确地说,我想更新包含类别的产品,我想更改产品中的类别:

更新函数

  async updateProduct(id: string, product: UpdateProductDto) {
try {
  await this.productRepository.update(id, product);
  await this.macroRepository.update(product.macro.id, product.macro);
  const updatedProduct = await this.productRepository.findOne(id);

  if (updatedProduct) {
    return updatedProduct;
  }

  return Promise.reject(new ProductNotFoundException(id));
} catch (error) {
  console.log(error)
  throw new ServerErrorException();
}

}

我错过了什么吗?

如果您想了解更多信息,我将代码发送到:github repo

【问题讨论】:

    标签: node.js postgresql typeorm nest


    【解决方案1】:

    我通过将update 方法更改为save 来解决此问题

    【讨论】:

      猜你喜欢
      • 2021-11-26
      • 1970-01-01
      • 2018-02-24
      • 1970-01-01
      • 2019-07-24
      • 1970-01-01
      • 2020-09-01
      • 1970-01-01
      • 2021-10-03
      相关资源
      最近更新 更多