* docs improvements and changes * updated module definition * modules + dml changes * fix build * fix vale error * fix lint errors * fixes to stripe docs * fix condition * fix condition * fix module defintion * fix checkout * disable UI action * change oas preview action * flatten provider module options * fix lint errors * add module link docs * pr comments fixes * fix vale error * change node engine version * links -> linkable * add note about database name * small fixes * link fixes * fix response code in api reference * added migrations step
85 lines
1.8 KiB
Plaintext
85 lines
1.8 KiB
Plaintext
export const metadata = {
|
||
title: `${pageNumber} Configure Data Model Properties`,
|
||
}
|
||
|
||
# {metadata.title}
|
||
|
||
In this chapter, you’ll learn how to configure data model properties.
|
||
|
||
## Property’s Default Value
|
||
|
||
Use the `default` method on a property's definition to specify the default value of a property.
|
||
|
||
For example:
|
||
|
||
export const defaultHighlights = [
|
||
["6", "default", "Set the default value to `black`."],
|
||
["9", "default", "Set the default value to `0`."]
|
||
]
|
||
|
||
```ts highlights={defaultHighlights}
|
||
import { model } from "@medusajs/utils"
|
||
|
||
const MyCustom = model.define("my_custom", {
|
||
color: model
|
||
.enum(["black", "white"])
|
||
.default("black"),
|
||
age: model
|
||
.number()
|
||
.default(0),
|
||
// ...
|
||
})
|
||
|
||
export default MyCustom
|
||
```
|
||
|
||
In this example, you set the default value of the `color` enum property to `black`, and that of the `age` number property to `0`.
|
||
|
||
---
|
||
|
||
## Nullable Property
|
||
|
||
Use the `nullable` method to indicate that a property’s value can be `null`.
|
||
|
||
For example:
|
||
|
||
export const nullableHighlights = [
|
||
["4", "nullable", "Configure the `price` property to allow `null` values."]
|
||
]
|
||
|
||
```ts highlights={nullableHighlights}
|
||
import { model } from "@medusajs/utils"
|
||
|
||
const MyCustom = model.define("my_custom", {
|
||
price: model.bigNumber().nullable(),
|
||
// ...
|
||
})
|
||
|
||
export default MyCustom
|
||
```
|
||
|
||
---
|
||
|
||
## Unique Property
|
||
|
||
The `unique` method indicates that a property’s value must be unique in the database through a unique index.
|
||
|
||
For example:
|
||
|
||
export const uniqueHighlights = [
|
||
["4", "unique", "Configure the `email` property to allow unique values only."]
|
||
]
|
||
|
||
```ts highlights={uniqueHighlights}
|
||
import { model } from "@medusajs/utils"
|
||
|
||
const User = model.define("user", {
|
||
email: model.text().unique(),
|
||
// ...
|
||
})
|
||
|
||
export default User
|
||
```
|
||
|
||
In this example, multiple users can’t have the same email.
|