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

fix(utils): Mikro orm repository update many to many should detach all items by default #9917

Merged
merged 3 commits into from
Nov 5, 2024

Conversation

adrien2p
Copy link
Member

@adrien2p adrien2p commented Nov 4, 2024

FIXES FRMW-2758

What
In the current state, when calling a module service update method and providing a partial array for a many to many collection,. mikor orm automatically handle detaching the items that are not present in the array. But in the case an empty array is provided, nothing happen when we would expect all items to be detached automatically. This PR aims at fixing this behaviour (which is expected by mikro orm).

Note
As per mikro orm documentation, when relying on auto detach from a collection (such as using remove or remove all), one query per removal will be created, which is not performant. The expectation would be that the end user manage his collection manually and be aware of what is happening by explicitly managing those cases. for example, providing explicit methods to detach X items from a collection instead of relying on updating deeply from top to bottom.
But in the end, we still provide this shortcut and the user can choose, for simple cases where not a lot of items are involve, to use or not this simili cascade behaviour.

Copy link

vercel bot commented Nov 4, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
medusa-dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 4, 2024 1:26pm
6 Skipped Deployments
Name Status Preview Comments Updated (UTC)
api-reference ⬜️ Ignored (Inspect) Nov 4, 2024 1:26pm
api-reference-v2 ⬜️ Ignored (Inspect) Visit Preview Nov 4, 2024 1:26pm
docs-ui ⬜️ Ignored (Inspect) Visit Preview Nov 4, 2024 1:26pm
docs-v2 ⬜️ Ignored (Inspect) Visit Preview Nov 4, 2024 1:26pm
medusa-docs ⬜️ Ignored (Inspect) Visit Preview Nov 4, 2024 1:26pm
resources-docs ⬜️ Ignored (Inspect) Visit Preview Nov 4, 2024 1:26pm

Copy link

changeset-bot bot commented Nov 4, 2024

🦋 Changeset detected

Latest commit: e1d1001

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 65 packages
Name Type
@medusajs/utils Patch
@medusajs/cli Patch
integration-tests-http Patch
@medusajs/medusa Patch
@medusajs/test-utils Patch
@medusajs/api-key Patch
@medusajs/auth Patch
@medusajs/cache-inmemory Patch
@medusajs/cache-redis Patch
@medusajs/cart Patch
@medusajs/currency Patch
@medusajs/customer Patch
@medusajs/event-bus-local Patch
@medusajs/event-bus-redis Patch
@medusajs/file Patch
@medusajs/fulfillment Patch
@medusajs/index Patch
@medusajs/inventory Patch
@medusajs/link-modules Patch
@medusajs/locking Patch
@medusajs/notification Patch
@medusajs/order Patch
@medusajs/payment Patch
@medusajs/pricing Patch
@medusajs/product Patch
@medusajs/promotion Patch
@medusajs/region Patch
@medusajs/sales-channel Patch
@medusajs/stock-location Patch
@medusajs/store Patch
@medusajs/tax Patch
@medusajs/user Patch
@medusajs/workflow-engine-inmemory Patch
@medusajs/workflow-engine-redis Patch
@medusajs/auth-emailpass Patch
@medusajs/auth-github Patch
@medusajs/auth-google Patch
@medusajs/file-local Patch
@medusajs/file-s3 Patch
@medusajs/fulfillment-manual Patch
@medusajs/locking-postgres Patch
@medusajs/locking-redis Patch
@medusajs/notification-local Patch
@medusajs/notification-sendgrid Patch
@medusajs/payment-stripe Patch
@medusajs/core-flows Patch
@medusajs/framework Patch
@medusajs/js-sdk Patch
@medusajs/modules-sdk Patch
@medusajs/orchestration Patch
@medusajs/types Patch
@medusajs/workflows-sdk Patch
@medusajs/medusa-oas-cli Patch
@medusajs/oas-github-ci Patch
@medusajs/telemetry Patch
@medusajs/admin-bundler Patch
@medusajs/admin-sdk Patch
@medusajs/admin-shared Patch
@medusajs/admin-vite-plugin Patch
@medusajs/dashboard Patch
@medusajs/icons Patch
@medusajs/toolbox Patch
@medusajs/ui-preset Patch
create-medusa-app Patch
medusa-dev-cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@thetutlage
Copy link
Contributor

Sounds good to me! Maybe, we can highlight this behaviour change in our changelog, incase someone was passing empty array during API calls and now they will see that this behaviour results in detach within the pivot table.

@adrien2p adrien2p marked this pull request as ready for review November 4, 2024 11:30
@adrien2p adrien2p requested a review from a team as a code owner November 4, 2024 11:30
@adrien2p
Copy link
Member Author

adrien2p commented Nov 4, 2024

/snapshot-this

1 similar comment
@adrien2p
Copy link
Member Author

adrien2p commented Nov 4, 2024

/snapshot-this

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

Successfully merging this pull request may close these issues.

3 participants