generate references (#7882)
This commit is contained in:
@@ -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)<[ExtractEntityRelations](../../../../types/DmlTypes/types/types.DmlTypes.ExtractEntityRelations/page.mdx)<Schema, \"hasOne\" \\| \"hasMany\">>","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"/>
|
||||
@@ -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)<Schema, string \\| [QueryCondition](../../../../types/DmlTypes/types/types.DmlTypes.QueryCondition/page.mdx)<Schema>>[]","description":"The index's configuration.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"on","type":"[InferIndexableProperties](../../../../types/DmlTypes/types/types.DmlTypes.InferIndexableProperties/page.mdx)<[IDmlEntity](../../../../types/DmlTypes/interfaces/types.DmlTypes.IDmlEntity/page.mdx)<TSchema>>[]","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"/>
|
||||
Reference in New Issue
Block a user