Rad*_*zak 2 postgresql node.js nest typeorm
我正在尝试更新数据,但出现如标题所示的错误。我的数据具有多对多关系,如下所示:
类别实体:
@ManyToMany(() => Product, (product: Product) => product.categories)
Run Code Online (Sandbox Code Playgroud)
公共产品:Product[];
产品实体:
@ManyToMany(() => Category, (category: Category) => category.products)
Run Code Online (Sandbox Code Playgroud)
@JoinTable() 公共类别:类别[];
更准确地说,我想更新包含类别的产品,我想更改产品中的类别:
更新功能
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();
}
Run Code Online (Sandbox Code Playgroud)
}
我错过了什么吗?
如果你想了解更多信息,我将我的代码放在:github repo
归档时间: |
|
查看次数: |
3031 次 |
最近记录: |