import { CodeTabs, CodeTab } from "docs-ui" export const metadata = { title: `Links between Region Module and Other Modules`, } # {metadata.title} This document showcases the module links defined between the Region Module and other commerce modules. ## Summary The Region Module has the following links to other modules: Read-only links are used to query data across modules, but the relations aren't stored in a pivot table in the database. - [`Region` data model \<\> `Cart` data model of the Cart Module](#cart-module). (Read-only) - [`Region` data model \<\> `Order` data model of the Order Module](#order-module). (Read-only) - [`Region` data model \<\> `PaymentProvider` data model of the Payment Module](#payment-module). --- ## Cart Module Medusa defines a read-only link between the `Region` data model and the [Cart Module](../../cart/page.mdx)'s `Cart` data model. This means you can retrieve the details of a region's carts, but you don't manage the links in a pivot table in the database. The region of a cart is determined by the `region_id` property of the `Cart` data model. ### Retrieve with Query To retrieve the carts of a region with [Query](!docs!/learn/fundamentals/module-links/query), pass `carts.*` in `fields`: ```ts const { data: regions } = await query.graph({ entity: "region", fields: [ "carts.*", ], }) // regions.carts ``` ```ts import { useQueryGraphStep } from "@medusajs/medusa/core-flows" // ... const { data: regions } = useQueryGraphStep({ entity: "region", fields: [ "carts.*", ], }) // regions.carts ``` --- ## Order Module Medusa defines a read-only link between the `Region` data model and the [Cart Module](../../cart/page.mdx)'s `Cart` data model. This means you can retrieve the details of a region's orders, but you don't manage the links in a pivot table in the database. The region of an order is determined by the `region_id` property of the `Order` data model. ### Retrieve with Query To retrieve the orders of a region with [Query](!docs!/learn/fundamentals/module-links/query), pass `orders.*` in `fields`: ```ts const { data: regions } = await query.graph({ entity: "region", fields: [ "orders.*", ], }) // regions.orders ``` ```ts import { useQueryGraphStep } from "@medusajs/medusa/core-flows" // ... const { data: regions } = useQueryGraphStep({ entity: "region", fields: [ "orders.*", ], }) // regions.orders ``` --- ## Payment Module You can specify for each region which payment providers are available for use. Medusa defines a module link between the `PaymentProvider` and the `Region` data models. ![A diagram showcasing an example of how resources from the Payment and Region modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1711569520/Medusa%20Resources/payment-region_jyo2dz.jpg) ### Retrieve with Query To retrieve the payment providers of a region with [Query](!docs!/learn/fundamentals/module-links/query), pass `payment_providers.*` in `fields`: ```ts const { data: regions } = await query.graph({ entity: "region", fields: [ "payment_providers.*", ], }) // regions.payment_providers ``` ```ts import { useQueryGraphStep } from "@medusajs/medusa/core-flows" // ... const { data: regions } = useQueryGraphStep({ entity: "region", fields: [ "payment_providers.*", ], }) // regions.payment_providers ``` ### Manage with Remote Link To manage the payment providers in a region, use [Remote Link](!docs!/learn/fundamentals/module-links/remote-link): ```ts import { Modules } from "@medusajs/framework/utils" // ... await remoteLink.create({ [Modules.REGION]: { region_id: "reg_123", }, [Modules.PAYMENT]: { payment_provider_id: "pp_stripe_stripe", }, }) ``` ```ts import { Modules } from "@medusajs/framework/utils" import { createRemoteLinkStep } from "@medusajs/medusa/core-flows" // ... createRemoteLinkStep({ [Modules.REGION]: { region_id: "reg_123", }, [Modules.PAYMENT]: { payment_provider_id: "pp_stripe_stripe", }, }) ```