generate references (#7882)

This commit is contained in:
Shahed Nasser
2024-07-01 16:02:36 +03:00
committed by GitHub
parent b9036eca1a
commit dd864da4e0
2424 changed files with 106679 additions and 116201 deletions

View File

@@ -0,0 +1,31 @@
---
slug: /references/data-model/model-methods/cascades
sidebar_label: cascades
---
import { TypeList } from "docs-ui"
# cascades Method - API Reference
This method configures which related data models an operation, such as deletion,
should be cascaded to.
For example, if a store is deleted, its product should also be deleted.
## Example
```ts
import { model } from "@medusajs/utils"
const Store = model.define("store", {
id: model.id(),
products: model.hasMany(() => Product),
})
.cascades({
delete: ["products"],
})
```
## Parameters
<TypeList types={[{"name":"options","type":"[EntityCascades](../../../../types/DmlTypes/types/types.DmlTypes.EntityCascades/page.mdx)&#60;[ExtractEntityRelations](../../../../types/DmlTypes/types/types.DmlTypes.ExtractEntityRelations/page.mdx)&#60;Schema, \"hasOne\" \\| \"hasMany\"&#62;&#62;","description":"The cascades configurations. They object's keys are the names of\nthe actions, such as `deleted`, and the value is an array of relations that the \naction should be cascaded to.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"delete","type":"Relationships","description":"The related models to delete when a record of this data model\nis deleted.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} sectionTitle="cascades"/>

View File

@@ -0,0 +1,81 @@
---
slug: /references/data-model/model-methods/indexes
sidebar_label: indexes
---
import { TypeList } from "docs-ui"
# indexes Method - API Reference
This method defines indices on the data model. An index can be on multiple columns
and have conditions.
## Example
An example of a simple index:
```ts
import { model } from "@medusajs/utils"
const MyCustom = model.define("my_custom", {
id: model.id(),
name: model.text(),
age: model.number()
}).indexes([
{
on: ["name", "age"],
},
])
export default MyCustom
```
To add a condition on the index, use the `where` option:
```ts
import { model } from "@medusajs/utils"
const MyCustom = model.define("my_custom", {
id: model.id(),
name: model.text(),
age: model.number()
}).indexes([
{
on: ["name", "age"],
where: {
age: 30
}
},
])
export default MyCustom
```
The condition can also be a negation. For example:
```ts
import { model } from "@medusajs/utils"
const MyCustom = model.define("my_custom", {
id: model.id(),
name: model.text(),
age: model.number()
}).indexes([
{
on: ["name", "age"],
where: {
age: {
$ne: 30
}
}
},
])
export default MyCustom
```
In this example, the index is created when the value of `age` doesn't equal `30`.
## Parameters
<TypeList types={[{"name":"indexes","type":"[EntityIndex](../../../../types/DmlTypes/types/types.DmlTypes.EntityIndex/page.mdx)&#60;Schema, string \\| [QueryCondition](../../../../types/DmlTypes/types/types.DmlTypes.QueryCondition/page.mdx)&#60;Schema&#62;&#62;[]","description":"The index's configuration.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"on","type":"[InferIndexableProperties](../../../../types/DmlTypes/types/types.DmlTypes.InferIndexableProperties/page.mdx)&#60;[IDmlEntity](../../../../types/DmlTypes/interfaces/types.DmlTypes.IDmlEntity/page.mdx)&#60;TSchema&#62;&#62;[]","description":"The list of properties to create the index on.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"The name of the index. If not provided,\nMedusa generates the name.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"unique","type":"`boolean`","description":"When enabled, a unique index is created on the specified\nproperties.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"where","type":"TWhere","description":"Conditions to restrict which records are indexed.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} sectionTitle="indexes"/>