|
1
|
--- |
|
2
|
sidebar_label: "retrieve" |
|
3
|
--- |
|
4
|
|
|
5
|
export const metadata = { |
|
6
|
title: `retrieve Method - Service Factory Reference`, |
|
7
|
} |
|
8
|
|
|
9
|
# {metadata.title} |
|
10
|
|
|
11
|
This method retrieves one record of a data model by its ID. |
|
12
|
|
|
13
|
The method's name is `retrieveDataModel`, where `DataModel` is the singular pascal-case name of the data model. |
|
14
|
|
|
15
|
## Retrieve a Record |
|
16
|
|
|
17
|
```ts |
|
18
|
const post = await postModuleService.retrievePost("123") |
|
19
|
``` |
|
20
|
|
|
21
|
### Parameters |
|
22
|
|
|
23
|
Pass the ID of the record to retrieve. |
|
24
|
|
|
25
|
### Returns |
|
26
|
|
|
27
|
The method returns the record as an object. |
|
28
|
|
|
29
|
--- |
|
30
|
|
|
31
|
## Retrieve a Record's Relations |
|
32
|
|
|
33
|
<Note> |
|
34
|
|
|
35
|
This applies to relations between data models of the same module. To retrieve linked records of different modules, use [Query](!docs!/learn/fundamentals/query). |
|
36
|
|
|
37
|
</Note> |
|
38
|
|
|
39
|
```ts |
|
40
|
const post = await postModuleService.retrievePost("123", { |
|
41
|
relations: ["author"], |
|
42
|
}) |
|
43
|
``` |
|
44
|
|
|
45
|
### Parameters |
|
46
|
|
|
47
|
To retrieve the data model with relations, pass an object with the property `relations` as the second parameter. `relations`'s value is an array of relation names. |
|
48
|
|
|
49
|
### Returns |
|
50
|
|
|
51
|
The method returns the record as an object. |
|
52
|
|
|
53
|
--- |
|
54
|
|
|
55
|
## Select Properties to Retrieve |
|
56
|
|
|
57
|
```ts |
|
58
|
const post = await postModuleService.retrievePost("123", { |
|
59
|
select: ["id", "name"], |
|
60
|
}) |
|
61
|
``` |
|
62
|
|
|
63
|
### Parameters |
|
64
|
|
|
65
|
By default, all of the record's properties are retrieved. To select specific ones, pass a `select` property in the second object parameter. Its value is an array of property names. |
|
66
|
|
|
67
|
### Returns |
|
68
|
|
|
69
|
The method returns the record as an object. |