Skip to content

Conversation

NicolasGorga
Copy link
Contributor

@NicolasGorga NicolasGorga commented Oct 16, 2025

Summary

Hey guys, the intention of this is to start the conversation around enhancing the public API of link, particularily around restore and delete. I spent many hours looking at the code in Link module and I can't say i completely understand it, but from what I understood, I managed to update it and make it work like I intended, although I have a few doubts abouts tests that i would have expected to see fail that aren't which doesn't make me all that confident.

This feature request made me think about what is included in the PR: #13715

What — What changes are introduced in this PR?

Added an optional options object to link module delete and restore methods

Please provide answer here

Why — Why are these changes relevant or necessary?

The idea behind this is to allow users to:

  1. Specify for a given module, to delete/restore all linked entities except for some, specified through the new options.exclude setting.
  2. Specify for a given module, to delete/restore only certain linked entities, specified through the new options.only setting.

Please provide answer here

How — How have these changes been implemented?

It was quite complex to understand what was going on, spent a few hours mapping out things and using Claude, so would like confirmation if what i did was okay.

It was weird to me why the already written test were passing, specifically for example Should call delete in cascade all the modules involved in the link when it asserts correctly:

expect(ProductModule.softDelete).toBeCalledWith(
      { id: ["var_123"] },
      { returnLinkableKeys: ["product_id", "variant_id"] },
      {}
    )

But on runtime I see the product variant is never soft deleted, only the relation links, like inventory item and price set, so would like to understand this (I wrote my tests for this based on the ones already there and don't understand why this assertion doesn't fail)

  • When only setting is specified,

Please provide answer here

Testing — How have these changes been tested, or how can the reviewer test the feature?

Included tests for both options, but have a few doubts specified in the previous point.


Examples

Provide examples or code snippets that demonstrate how this feature works, or how it can be used in practice.
This helps with documentation and ensures maintainers can quickly understand and verify the change.

// Soft delete only price set relation links to the variant, but avoid removing any inventory existent ones
await link.delete({[Modules.PRODUCT]: {
    variant_id: 'var123'
}}, {
          only:['pricing'],
        });
        
// Soft delete all relation links to the variant except for pricing ones, which would delete the inventory ones
await link.delete({[Modules.PRODUCT]: {
    variant_id: 'var123'
}}, {
          exclude:['pricing'],
        });

 // Restore only soft deleted price set relation linked to the variant. It wouldn't restore eny inventory links that were previously soft deleted
 await link.restore({[Modules.PRODUCT]: {
    variant_id: 'var123'
}}, {
          only:['pricing'],
        });
        
 // Restore all soft deleted linked relations to the variant, except for price ones. It wouldn't restore any price links that were previously soft deleted
await link.restore({[Modules.PRODUCT]: {
    variant_id: 'var123'
}}, {
          exclude:['pricing'],
        });

Checklist

Please ensure the following before requesting a review:

  • I have added a changeset for this PR
    • Every non-breaking change should be marked as a patch
    • To add a changeset, run yarn changeset and follow the prompts
  • The changes are covered by relevant tests
  • I have verified the code works as intended locally
  • I have linked the related issue(s) if applicable

Additional Context

Add any additional context, related issues, or references that might help the reviewer understand this PR.

Copy link

changeset-bot bot commented Oct 16, 2025

⚠️ No Changeset found

Latest commit: d0d8143

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Copy link

vercel bot commented Oct 16, 2025

@NicolasGorga is attempting to deploy a commit to the medusajs Team on Vercel.

A member of the Team first needs to authorize it.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant