Files

101 lines
2.6 KiB
Plaintext

import { CodeTabs, CodeTab, Table } from "docs-ui"
export const metadata = {
title: `Links between Currency Module and Other Modules`,
}
# {metadata.title}
This document showcases the module links defined between the Currency Module and other Commerce Modules.
## Summary
The Currency Module has the following links to other modules:
<Note title="Tip">
Read-only links are used to query data across modules, but the relations aren't stored in a pivot table in the database.
</Note>
<Table>
<Table.Header>
<Table.Row>
<Table.HeaderCell>
First Data Model
</Table.HeaderCell>
<Table.HeaderCell>
Second Data Model
</Table.HeaderCell>
<Table.HeaderCell>
Type
</Table.HeaderCell>
<Table.HeaderCell>
Description
</Table.HeaderCell>
</Table.Row>
</Table.Header>
<Table.Body>
<Table.Row>
<Table.Cell>
[StoreCurrency](/references/store/models/StoreCurrency) in [Store Module](../../store/page.mdx)
</Table.Cell>
<Table.Cell>
[Currency](/references/currency/models/Currency)
</Table.Cell>
<Table.Cell>
Read-only - has one
</Table.Cell>
<Table.Cell>
[Learn more](#store-module)
</Table.Cell>
</Table.Row>
</Table.Body>
</Table>
---
## Store Module
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.
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.
### Retrieve with Query
To retrieve the details of a store's currencies with [Query](!docs!/learn/fundamentals/module-links/query), pass `supported_currencies.currency.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: stores } = await query.graph({
entity: "store",
fields: [
"supported_currencies.currency.*",
],
})
// stores[0].supported_currencies[0].currency
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: stores } = useQueryGraphStep({
entity: "store",
fields: [
"supported_currencies.currency.*",
],
})
// stores[0].supported_currencies[0].currency
```
</CodeTab>
</CodeTabs>