- Get Started
- Product
- Resources
- Tools & SDKs
- Framework
- Reference
- Get Started
- Product
- Resources
- Tools & SDKs
- Framework
- Reference
4.4.2. Remote Link
In this chapter, you’ll learn what the remote link is and how to use it to manage links.
What is the Remote Link?#
The remote link is a class with utility methods to manage links between data models. It’s registered in the Medusa container under the remoteLink
registration name.
For example:
You can use its methods to manage links, such as create or delete links.
Create Link#
To create a link between records of two data models, use the create
method of the remote link.
For example:
The create
method accepts as a parameter an object. The object’s keys are the names of the linked modules.
The value of each module’s property is an object, whose keys are of the format {data_model_snake_name}_id
, and values are the IDs of the linked record.
So, in the example above, you link a record of the MyCustom
data model in a hello
module to a Product
record in the Product Module.
Dismiss Link#
To remove a link between records of two data models, use the dismiss
method of the remote link.
For example:
The dismiss
method accepts the same parameter type as the create method.
Cascade Delete Linked Records#
If a record is deleted, use the delete
method of the remote link to delete all linked records.
For example:
This deletes all records linked to the deleted product.
Restore Linked Records#
If a record that was previously soft-deleted is now restored, use the restore
method of the remote link to restore all linked records.
For example: