|
1
|
--- |
|
2
|
sidebar_label: "create" |
|
3
|
--- |
|
4
|
|
|
5
|
export const metadata = { |
|
6
|
title: `create Method - Service Factory Reference`, |
|
7
|
} |
|
8
|
|
|
9
|
# {metadata.title} |
|
10
|
|
|
11
|
This method of a module's service creates one or more records of a data model. |
|
12
|
|
|
13
|
The method's name is of the format `createDataModel`, where `DataModel` is the plural pascal-case name of the data model. |
|
14
|
|
|
15
|
## Create One Record |
|
16
|
|
|
17
|
```ts |
|
18
|
const post = await postModuleService.createPosts({ |
|
19
|
name: "My Post", |
|
20
|
published_at: new Date(), |
|
21
|
metadata: { |
|
22
|
external_id: "1234", |
|
23
|
}, |
|
24
|
}) |
|
25
|
``` |
|
26
|
|
|
27
|
If an object is passed to the method, the created record object is returned. |
|
28
|
|
|
29
|
--- |
|
30
|
|
|
31
|
## Create Multiple Records |
|
32
|
|
|
33
|
```ts |
|
34
|
const posts = await postModuleService.createPosts([ |
|
35
|
{ |
|
36
|
name: "My Post", |
|
37
|
published_at: new Date(), |
|
38
|
}, |
|
39
|
{ |
|
40
|
name: "My Other Post", |
|
41
|
published_at: new Date(), |
|
42
|
}, |
|
43
|
]) |
|
44
|
``` |
|
45
|
|
|
46
|
If an array of objects is passed to the method, an array containing the created records is returned. |