【发布时间】: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