Radosław Łuczak
Radosław Łuczak

Reputation: 91

Cannot query across many to many relations NestJS

I'am trying updated data but I get error like in title. My data have many to many relations like bellow:

Category entity:

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

public products: Product[];

Product Entity:

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

@JoinTable() public categories: Category[];

To be more precise I want to update Product, who contain category, I want to change category in product:

function to update

  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();
}

}

Do I miss something?

If you want to more info I put my code to: github repo

Upvotes: 2

Views: 3372

Answers (1)

Radosław Łuczak
Radosław Łuczak

Reputation: 91

I resolve this problem by changing update method to save

Upvotes: 5

Related Questions