Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot remove many to many association using the update method #9547

Open
yuning-zhang opened this issue Oct 14, 2024 · 0 comments
Open

Cannot remove many to many association using the update method #9547

yuning-zhang opened this issue Oct 14, 2024 · 0 comments

Comments

@yuning-zhang
Copy link

Bug report

Describe the bug

Service Factory update method cannot remove many to many association. Using the example in the doc manage many-to-many relationship, see the following code to completely remove associations.

const product = await helloModuleService.updateProducts({
  id: "123",
  orders: [],
})

By passing an empty array, this should remove all orders from the product. Instead, it doesn't change anything. As long as there's one element in the array, updating association seems to work. But with an empty array, associations are not updated as one would expect.

System information

Medusa version (including plugins): rc-02
Node.js version: v20
Database: Supabase
Operating system: MacOS 14
Browser (if relevant):

Steps to reproduce the behavior

  1. Create a many to many relationship such as orders <-> products
  2. Create an association
const product = await helloModuleService.updateProducts({
  id: "123",
  orders: ["321"],
})
  1. Attempt to remove association by passing an empty orders array
const product = await helloModuleService.updateProducts({
  id: "123",
  orders: [],
})
  1. Fetch orders and see that order id "321" is still associated with product "123"

Expected behavior

Passing an empty array to remove any many to many association

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant