docs: document composite indices + primary key changes (#7902)

This commit is contained in:
Shahed Nasser
2024-07-02 12:34:44 +03:00
committed by GitHub
parent a84e5a6ced
commit 6cb28eedf7
13 changed files with 205 additions and 93 deletions
@@ -6,35 +6,25 @@ export const metadata = {
In this chapter, youll learn how to configure the primary key of a data model.
## id Property
A property defined with the `id` method is, by default, considered the data models primary key.
---
## primaryKey Method
To set any `text` or `number` property as a primary key, use the `primaryKey` method.
To set any `id`, `text`, or `number` property as a primary key, use the `primaryKey` method.
For example:
export const highlights = [
["4", "primaryKey", "Define the `code` property to be the data model's primary key."]
["4", "primaryKey", "Define the `id` property to be the data model's primary key."]
]
```ts highlights={highlights}
import { model } from "@medusajs/utils"
const MyCustom = model.define("my_custom", {
code: model.text().primaryKey(),
id: model.id().primaryKey(),
// ...
})
export default MyCustom
```
<Note>
A property thats defined with the `primaryKey` method takes precedence over an `id` property.
</Note>
In the example above, the `id` property is defined as the data model's primary key.