1 export const metadata = {
2 title: `${pageNumber} Module Link Direction`,
3 }
4
5 # {metadata.title}
6
7 In this chapter, you'll learn about the difference in module link directions, and which to use based on your use case.
8
9 <Note>
10
11 The details in this chapter don't apply to [Read-Only Module Links](../read-only/page.mdx). Refer to the [Read-Only Module Links chapter](../read-only/page.mdx) for more information on read-only links and their direction.
12
13 </Note>
14
15 ## Link Direction
16
17 The module link's direction depends on the order you pass the data model configuration parameters to `defineLink`.
18
19 For example, the following defines a link from the Blog Module's `post` data model to the Product Module's `product` data model:
20
21 ```ts
22 export default defineLink(
23 BlogModule.linkable.post,
24 ProductModule.linkable.product
25 )
26 ```
27
28 Whereas the following defines a link from the Product Module's `product` data model to the Blog Module's `post` data model:
29
30 ```ts
31 export default defineLink(
32 ProductModule.linkable.product,
33 BlogModule.linkable.post
34 )
35 ```
36
37 The above links are two different links that serve different purposes.
38
39 ---
40
41 ## Which Link Direction to Use?
42
43 ### Extend Data Models
44
45 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.
46
47 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:
48
49 ```ts
50 export default defineLink(
51 ProductModule.linkable.product,
52 BlogModule.linkable.subtitle
53 )
54 ```
55
56 ### Associate Data Models
57
58 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.
59
60 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`:
61
62 ```ts
63 export default defineLink(
64 BlogModule.linkable.post,
65 ProductModule.linkable.product
66 )
67 ```