docs: document checks examples + migrations naming convention (#13052)
This commit is contained in:
@@ -58,6 +58,32 @@ const Post = model.define("post", {
|
||||
export default Post
|
||||
```
|
||||
|
||||
#### Limit Text Length
|
||||
|
||||
To limit the allowed length of a `text` property, use the [checks method](../check-constraints/page.mdx).
|
||||
|
||||
For example, to limit the `name` property to a maximum of 50 characters:
|
||||
|
||||
export const textLengthHighlights = [
|
||||
["7", "checks", "Add check constraints to the data model."],
|
||||
]
|
||||
|
||||
```ts highlights={textLengthHighlights}
|
||||
import { model } from "@medusajs/framework/utils"
|
||||
|
||||
const Post = model.define("post", {
|
||||
name: model.text(),
|
||||
// ...
|
||||
})
|
||||
.checks([
|
||||
(columns) => `${columns.name.length} <= 50`,
|
||||
])
|
||||
|
||||
export default Post
|
||||
```
|
||||
|
||||
This will add a database check constraint that ensures the `name` property of a record does not exceed 50 characters. If a record with a longer `name` is attempted to be inserted, an error will be thrown.
|
||||
|
||||
### number
|
||||
|
||||
The `number` method defines a number property.
|
||||
|
||||
Reference in New Issue
Block a user