|
1
|
--- |
|
2
|
sidebar_label: "no-reserved-default-properties-in-model" |
|
3
|
--- |
|
4
|
|
|
5
|
export const metadata = { |
|
6
|
title: `no-reserved-default-properties-in-model - ESLint plugin rules`, |
|
7
|
} |
|
8
|
|
|
9
|
# {metadata.title} |
|
10
|
|
|
11
|
This rule disallows redefining the reserved default properties `created_at`, `updated_at`, and `deleted_at` in `model.define`. |
|
12
|
|
|
13
|
## Severity |
|
14
|
|
|
15
|
`error`. This rule is enabled in the [recommended](../../page.mdx#recommended) preset. |
|
16
|
|
|
17
|
## What it Targets |
|
18
|
|
|
19
|
This rule targets data model files in your project's `src/modules` directory. It reports a `created_at`, `updated_at`, or `deleted_at` property in a `model.define` schema, since Medusa adds these automatically. |
|
20
|
|
|
21
|
The following code is reported by the rule: |
|
22
|
|
|
23
|
```ts title="src/modules/blog/models/post.ts" |
|
24
|
import { model } from "@medusajs/framework/utils" |
|
25
|
|
|
26
|
export const Post = model.define("post", { |
|
27
|
id: model.id().primaryKey(), |
|
28
|
created_at: model.dateTime(), |
|
29
|
}) |
|
30
|
``` |
|
31
|
|
|
32
|
Instead, remove the reserved property: |
|
33
|
|
|
34
|
```ts title="src/modules/blog/models/post.ts" |
|
35
|
import { model } from "@medusajs/framework/utils" |
|
36
|
|
|
37
|
export const Post = model.define("post", { |
|
38
|
id: model.id().primaryKey(), |
|
39
|
}) |
|
40
|
``` |
|
41
|
|
|
42
|
## Why it's Important |
|
43
|
|
|
44
|
Medusa automatically adds `created_at`, `updated_at`, and `deleted_at` to every data model. Redefining them in your schema is redundant and can conflict with the auto-added columns. |
|
45
|
|
|
46
|
Learn more in the [Data Models documentation](!docs!/learn/fundamentals/data-models). |
|
47
|
|
|
48
|
## Fixable |
|
49
|
|
|
50
|
This rule is auto-fixable. Run the linter with the `--fix` option to apply the fix automatically. |