Raw
1 import { CodeTabs, CodeTab, Table } from "docs-ui"
2
3 export const metadata = {
4 title: `Links between Currency Module and Other Modules`,
5 }
6
7 # {metadata.title}
8
9 This document showcases the module links defined between the Currency Module and other Commerce Modules.
10
11 ## Summary
12
13 The Currency Module has the following links to other modules:
14
15 <Note title="Tip">
16
17 Read-only links are used to query data across modules, but the relations aren't stored in a pivot table in the database.
18
19 </Note>
20
21 <Table>
22 <Table.Header>
23 <Table.Row>
24 <Table.HeaderCell>
25 First Data Model
26 </Table.HeaderCell>
27 <Table.HeaderCell>
28 Second Data Model
29 </Table.HeaderCell>
30 <Table.HeaderCell>
31 Type
32 </Table.HeaderCell>
33 <Table.HeaderCell>
34 Description
35 </Table.HeaderCell>
36 </Table.Row>
37 </Table.Header>
38 <Table.Body>
39 <Table.Row>
40 <Table.Cell>
41 [StoreCurrency](/references/store/models/StoreCurrency) in [Store Module](../../store/page.mdx)
42 </Table.Cell>
43 <Table.Cell>
44 [Currency](/references/currency/models/Currency)
45 </Table.Cell>
46 <Table.Cell>
47 Read-only - has one
48 </Table.Cell>
49 <Table.Cell>
50 [Learn more](#store-module)
51 </Table.Cell>
52 </Table.Row>
53 </Table.Body>
54 </Table>
55 ---
56
57 ## Store Module
58
59 The Store Module has a `Currency` data model that stores the supported currencies of a store. However, these currencies don't hold all the details of a currency, such as its name or symbol.
60
61 Instead, Medusa defines a read-only link between the [Store Module](../../store/page.mdx)'s `StoreCurrency` data model and the Currency Module's `Currency` data model. Because the link is read-only from the `Store`'s side, you can only retrieve the details of a store's supported currencies, and not the other way around.
62
63 ### Retrieve with Query
64
65 To retrieve the details of a store's currencies with [Query](!docs!/learn/fundamentals/query), pass `supported_currencies.currency.*` in `fields`:
66
67 <CodeTabs group="relation-query">
68 <CodeTab label="query.graph" value="method">
69
70 ```ts
71 const { data: stores } = await query.graph({
72 entity: "store",
73 fields: [
74 "supported_currencies.currency.*",
75 ],
76 })
77
78 // stores[0].supported_currencies[0].currency
79 ```
80
81 </CodeTab>
82 <CodeTab label="useQueryGraphStep" value="step">
83
84 ```ts
85 import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
86
87 // ...
88
89 const { data: stores } = useQueryGraphStep({
90 entity: "store",
91 fields: [
92 "supported_currencies.currency.*",
93 ],
94 })
95
96 // stores[0].supported_currencies[0].currency
97 ```
98
99 </CodeTab>
100 </CodeTabs>