3.3.1. Module Link Direction

In this chapter, you'll learn about the difference in module link directions, and which to use based on your use case.

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:

Code
1export default defineLink(2  HelloModule.linkable.myCustom,3  ProductModule.linkable.product4)

Whereas the following defines a link from the Product Module's product data model to the helloModuleService's myCustom data model:

Code
1export default defineLink(2  ProductModule.linkable.product,3  HelloModule.linkable.myCustom4)

The above links are two different links that serve different purposes.


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, consider you want to add a subtitle custom field to the product data model. To do that, you define a Subtitle data model in your module, then define a link from the Product data model to it:

Code
1export default defineLink(2  ProductModule.linkable.product,3  HelloModule.linkable.subtitle4)

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, consider you have Post data model representing a blog post, and you want to associate a blog post with a product. To do that, define a link from the Post data model to Product:

Code
1export default defineLink(2  HelloModule.linkable.post,3  ProductModule.linkable.product4)
Was this chapter helpful?
Edit this page