www/apps/resources/app/service-factory-reference/methods/retrieve/page.mdx
export const metadata = {
title: retrieve Method - Service Factory Reference,
}
This method retrieves one record of a data model by its ID.
The method's name is retrieveDataModel, where DataModel is the singular pascal-case name of the data model.
const post = await postModuleService.retrievePost("123")
Pass the ID of the record to retrieve.
The method returns the record as an object.
This applies to relations between data models of the same module. To retrieve linked records of different modules, use Query.
</Note>const post = await postModuleService.retrievePost("123", {
relations: ["author"],
})
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.
The method returns the record as an object.
const post = await postModuleService.retrievePost("123", {
select: ["id", "name"],
})
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.
The method returns the record as an object.