docs: fix information related to link directions (#8236)
* docs: fix keys passed to remoteLink.create and remoteLink.dismiss * updated hello module name + clarified note * added details about module link directions * fix lint errors
This commit is contained in:
@@ -0,0 +1,61 @@
|
|||||||
|
export const metadata = {
|
||||||
|
title: `${pageNumber} Module Link Direction`,
|
||||||
|
}
|
||||||
|
|
||||||
|
# {metadata.title}
|
||||||
|
|
||||||
|
In this chapter, you'll learn about difference in module link directions, and which to use based on your use case.
|
||||||
|
|
||||||
|
## Link Direction
|
||||||
|
|
||||||
|
The module link's direction depends on the order you pass the data model configuration parameters to `defineLink`.
|
||||||
|
|
||||||
|
For example, the following defines a link from the `helloModuleService`'s `myCustom` data model to the Product Module's `product` data model:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
export default defineLink(
|
||||||
|
HelloModule.linkable.myCustom,
|
||||||
|
ProductModule.linkable.product
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
Whereas the following defines a link from the Product Module's `product` data model to the `helloModuleService`'s `myCustom` data model:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
export default defineLink(
|
||||||
|
ProductModule.linkable.product,
|
||||||
|
HelloModule.linkable.myCustom
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
The above links are two different links that serve different purposes.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Which Link Direction to Use?
|
||||||
|
|
||||||
|
### Extend Data Models
|
||||||
|
|
||||||
|
If you're adding a link to a data model to extend it and add new fields, define the link from the main data model to the custom data model.
|
||||||
|
|
||||||
|
For example, if the `myCustom` data model adds new fields to the `product` data model, define the link from `product` to `myCustom`:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
export default defineLink(
|
||||||
|
ProductModule.linkable.product,
|
||||||
|
HelloModule.linkable.myCustom
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Associate Data Models
|
||||||
|
|
||||||
|
If you're linking data models to indicate an association between them, define the link from the custom data model to the main data model.
|
||||||
|
|
||||||
|
For example, if the `myCustom` data model is associated to the `product` data model, define the link from `myCustom` to `product`:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
export default defineLink(
|
||||||
|
HelloModule.linkable.myCustom,
|
||||||
|
ProductModule.linkable.product
|
||||||
|
)
|
||||||
|
```
|
||||||
@@ -51,8 +51,8 @@ import ProductModule from "@medusajs/product"
|
|||||||
import { defineLink } from "@medusajs/utils"
|
import { defineLink } from "@medusajs/utils"
|
||||||
|
|
||||||
export default defineLink(
|
export default defineLink(
|
||||||
HelloModule.linkable.myCustom,
|
ProductModule.linkable.product,
|
||||||
ProductModule.linkable.product
|
HelloModule.linkable.myCustom
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -86,11 +86,11 @@ import ProductModule from "@medusajs/product"
|
|||||||
import { defineLink } from "@medusajs/utils"
|
import { defineLink } from "@medusajs/utils"
|
||||||
|
|
||||||
export default defineLink(
|
export default defineLink(
|
||||||
|
ProductModule.linkable.product,
|
||||||
{
|
{
|
||||||
linkable: HelloModule.linkable.myCustom,
|
linkable: HelloModule.linkable.myCustom,
|
||||||
isList: true,
|
isList: true,
|
||||||
},
|
}
|
||||||
ProductModule.linkable.product
|
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -132,11 +132,11 @@ import ProductModule from "@medusajs/product"
|
|||||||
import { defineLink } from "@medusajs/utils"
|
import { defineLink } from "@medusajs/utils"
|
||||||
|
|
||||||
export default defineLink(
|
export default defineLink(
|
||||||
|
ProductModule.linkable.product,
|
||||||
{
|
{
|
||||||
linkable: HelloModule.linkable.myCustom,
|
linkable: HelloModule.linkable.myCustom,
|
||||||
deleteCascades: true,
|
deleteCascades: true,
|
||||||
},
|
}
|
||||||
ProductModule.linkable.product
|
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ await remoteLink.create({
|
|||||||
[Modules.PRODUCT]: {
|
[Modules.PRODUCT]: {
|
||||||
product_id: "prod_123",
|
product_id: "prod_123",
|
||||||
},
|
},
|
||||||
"hello": {
|
"helloModuleService": {
|
||||||
my_custom_id: "mc_123",
|
my_custom_id: "mc_123",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -69,6 +69,12 @@ await remoteLink.create({
|
|||||||
|
|
||||||
The `create` method accepts as a parameter an object. The object’s keys are the names of the linked modules.
|
The `create` method accepts as a parameter an object. The object’s keys are the names of the linked modules.
|
||||||
|
|
||||||
|
<Note title="Important">
|
||||||
|
|
||||||
|
The keys (names of linked modules) must be in the same direction of the link definition.
|
||||||
|
|
||||||
|
</Note>
|
||||||
|
|
||||||
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.
|
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.
|
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.
|
||||||
@@ -90,7 +96,7 @@ await remoteLink.dismiss({
|
|||||||
[Modules.PRODUCT]: {
|
[Modules.PRODUCT]: {
|
||||||
product_id: "prod_123",
|
product_id: "prod_123",
|
||||||
},
|
},
|
||||||
"hello": {
|
"helloModuleService": {
|
||||||
my_custom_id: "mc_123",
|
my_custom_id: "mc_123",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -98,6 +104,12 @@ await remoteLink.dismiss({
|
|||||||
|
|
||||||
The `dismiss` method accepts the same parameter type as the [create method](#create-link).
|
The `dismiss` method accepts the same parameter type as the [create method](#create-link).
|
||||||
|
|
||||||
|
<Note title="Important">
|
||||||
|
|
||||||
|
The keys (names of linked modules) must be in the same direction of the link definition.
|
||||||
|
|
||||||
|
</Note>
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Cascade Delete Linked Records
|
## Cascade Delete Linked Records
|
||||||
|
|||||||
@@ -114,6 +114,10 @@ export const sidebar = sidebarAttachHrefCommonOptions(
|
|||||||
path: "/advanced-development/modules/module-links",
|
path: "/advanced-development/modules/module-links",
|
||||||
title: "Module Links",
|
title: "Module Links",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: "/advanced-development/modules/module-link-directions",
|
||||||
|
title: "Module Link Direction",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: "/advanced-development/modules/remote-link",
|
path: "/advanced-development/modules/remote-link",
|
||||||
title: "Remote Link",
|
title: "Remote Link",
|
||||||
|
|||||||
Reference in New Issue
Block a user