docs: use mappedBy property for all relationship types (#12973)
This commit is contained in:
@@ -1245,12 +1245,14 @@ Learn more in [this documentation](!docs!/learn/fundamentals/data-models/propert
|
||||
|
||||
The following creates a one-to-one relationship between the `User` and `Email` data models:
|
||||
|
||||
```ts highlights={[["5", "hasOne"], ["10", "belongsTo"]]}
|
||||
```ts highlights={[["5", "hasOne"], ["12", "belongsTo"]]}
|
||||
import { model } from "@medusajs/framework/utils"
|
||||
|
||||
const User = model.define("user", {
|
||||
id: model.id().primaryKey(),
|
||||
email: model.hasOne(() => Email),
|
||||
email: model.hasOne(() => Email, {
|
||||
mappedBy: "user",
|
||||
}),
|
||||
})
|
||||
|
||||
const Email = model.define("email", {
|
||||
@@ -1267,12 +1269,14 @@ Learn more in [this documentation](!docs!/learn/fundamentals/data-models/relatio
|
||||
|
||||
The following creates a one-to-many relationship between the `Store` and `Product` data models:
|
||||
|
||||
```ts highlights={[["5", "hasMany"], ["10", "belongsTo"]]}
|
||||
```ts highlights={[["5", "hasMany"], ["12", "belongsTo"]]}
|
||||
import { model } from "@medusajs/framework/utils"
|
||||
|
||||
const Store = model.define("store", {
|
||||
id: model.id().primaryKey(),
|
||||
products: model.hasMany(() => Product),
|
||||
products: model.hasMany(() => Product, {
|
||||
mappedBy: "store",
|
||||
}),
|
||||
})
|
||||
|
||||
const Product = model.define("product", {
|
||||
@@ -1313,13 +1317,15 @@ Learn more in [this documentation](!docs!/learn/fundamentals/data-models/relatio
|
||||
|
||||
To configure cascade on a data model:
|
||||
|
||||
```ts highlights={[["7", "cascades"]]}
|
||||
```ts highlights={[["10", "cascades"]]}
|
||||
import { model } from "@medusajs/framework/utils"
|
||||
// Product import
|
||||
import Product from "./product"
|
||||
|
||||
const Store = model.define("store", {
|
||||
id: model.id().primaryKey(),
|
||||
products: model.hasMany(() => Product),
|
||||
products: model.hasMany(() => Product, {
|
||||
mappedBy: "store",
|
||||
}),
|
||||
})
|
||||
.cascades({
|
||||
delete: ["products"],
|
||||
|
||||
@@ -239,7 +239,9 @@ export const Wishlist = model.define("wishlist", {
|
||||
id: model.id().primaryKey(),
|
||||
customer_id: model.text(),
|
||||
sales_channel_id: model.text(),
|
||||
items: model.hasMany(() => WishlistItem),
|
||||
items: model.hasMany(() => WishlistItem, {
|
||||
mappedBy: "wishlist",
|
||||
}),
|
||||
})
|
||||
.indexes([
|
||||
{
|
||||
|
||||
@@ -122,7 +122,9 @@ export const Restaurant = model.define("restaurant", {
|
||||
email: model.text(),
|
||||
address: model.text(),
|
||||
image_url: model.text().nullable(),
|
||||
admins: model.hasMany(() => RestaurantAdmin),
|
||||
admins: model.hasMany(() => RestaurantAdmin, {
|
||||
mappedBy: "restaurant",
|
||||
}),
|
||||
})
|
||||
```
|
||||
|
||||
|
||||
@@ -135,7 +135,9 @@ const Vendor = model.define("vendor", {
|
||||
handle: model.text().unique(),
|
||||
name: model.text(),
|
||||
logo: model.text().nullable(),
|
||||
admins: model.hasMany(() => VendorAdmin),
|
||||
admins: model.hasMany(() => VendorAdmin, {
|
||||
mappedBy: "vendor",
|
||||
}),
|
||||
})
|
||||
|
||||
export default Vendor
|
||||
|
||||
@@ -114,7 +114,7 @@ export const generatedEditDates = {
|
||||
"app/recipes/digital-products/examples/standard/page.mdx": "2025-04-24T15:41:05.364Z",
|
||||
"app/recipes/digital-products/page.mdx": "2025-05-20T07:51:40.719Z",
|
||||
"app/recipes/ecommerce/page.mdx": "2025-06-24T08:50:10.116Z",
|
||||
"app/recipes/marketplace/examples/vendors/page.mdx": "2025-07-14T13:59:32.168Z",
|
||||
"app/recipes/marketplace/examples/vendors/page.mdx": "2025-07-16T09:58:59.793Z",
|
||||
"app/recipes/marketplace/page.mdx": "2025-05-20T07:51:40.721Z",
|
||||
"app/recipes/multi-region-store/page.mdx": "2025-05-20T07:51:40.721Z",
|
||||
"app/recipes/omnichannel/page.mdx": "2025-05-20T07:51:40.722Z",
|
||||
@@ -569,7 +569,7 @@ export const generatedEditDates = {
|
||||
"app/medusa-cli/commands/start/page.mdx": "2025-04-08T11:56:15.522Z",
|
||||
"app/medusa-cli/commands/telemtry/page.mdx": "2025-01-16T09:51:24.323Z",
|
||||
"app/medusa-cli/commands/user/page.mdx": "2024-08-28T10:44:52.489Z",
|
||||
"app/recipes/marketplace/examples/restaurant-delivery/page.mdx": "2025-07-14T10:32:58.301Z",
|
||||
"app/recipes/marketplace/examples/restaurant-delivery/page.mdx": "2025-07-16T09:58:31.748Z",
|
||||
"references/types/HttpTypes/interfaces/types.HttpTypes.AdminCreateCustomerGroup/page.mdx": "2024-12-09T13:21:33.569Z",
|
||||
"references/types/HttpTypes/interfaces/types.HttpTypes.AdminCreateReservation/page.mdx": "2025-04-11T09:04:47.498Z",
|
||||
"references/types/HttpTypes/interfaces/types.HttpTypes.AdminCustomerGroup/page.mdx": "2025-05-20T07:51:41.059Z",
|
||||
@@ -2166,7 +2166,7 @@ export const generatedEditDates = {
|
||||
"app/commerce-modules/sales-channel/links-to-other-modules/page.mdx": "2025-04-17T16:00:09.483Z",
|
||||
"app/commerce-modules/stock-location/links-to-other-modules/page.mdx": "2025-04-17T16:02:51.467Z",
|
||||
"app/commerce-modules/store/links-to-other-modules/page.mdx": "2025-04-17T16:03:16.419Z",
|
||||
"app/examples/page.mdx": "2025-04-17T08:50:17.036Z",
|
||||
"app/examples/page.mdx": "2025-07-16T09:53:26.163Z",
|
||||
"app/medusa-cli/commands/build/page.mdx": "2024-11-11T11:00:49.665Z",
|
||||
"app/js-sdk/page.mdx": "2025-05-26T15:08:16.590Z",
|
||||
"references/js_sdk/admin/Admin/properties/js_sdk.admin.Admin.apiKey/page.mdx": "2025-05-20T07:51:40.924Z",
|
||||
@@ -5832,7 +5832,7 @@ export const generatedEditDates = {
|
||||
"references/core_flows/types/core_flows.ThrowUnlessPaymentCollectionNotePaidInput/page.mdx": "2025-06-25T10:11:33.516Z",
|
||||
"references/core_flows/types/core_flows.ValidatePaymentsRefundStepInput/page.mdx": "2025-06-25T10:11:34.185Z",
|
||||
"references/core_flows/types/core_flows.ValidateRefundStepInput/page.mdx": "2025-06-25T10:11:34.177Z",
|
||||
"app/plugins/guides/wishlist/page.mdx": "2025-05-20T07:51:40.717Z",
|
||||
"app/plugins/guides/wishlist/page.mdx": "2025-07-16T09:54:20.345Z",
|
||||
"app/plugins/page.mdx": "2025-02-26T11:39:25.709Z",
|
||||
"app/admin-components/components/data-table/page.mdx": "2025-03-03T14:55:58.556Z",
|
||||
"references/order_models/variables/order_models.Order/page.mdx": "2025-07-14T09:31:48.410Z",
|
||||
|
||||
Reference in New Issue
Block a user