restore Method - Service Factory Reference

This method of a module's service restores one or more records of a data model that were soft-deleted.

The method's name is of the format restoreDataModel, where DataModel is the plural pascal-case name of the data model.

Restore One Record#

Code
const restoredPosts = await postModuleService.restorePosts("123")

Parameters#

To restore one record, pass its ID as a parameter to the method.

Returns#

The method returns an object, whose keys are of the format {camel_case_data_model_name}_id, and their values are arrays of restored records' IDs.

For example, the returned object of the above example is:

Code
{
  "post_id": ["123"],
}

Restore Multiple Records#

Code
const restoredPosts = await postModuleService.restorePosts([
  "123",
  "321",
])

Parameters#

To restore multiple records, pass an array of IDs as a parameter to the method.

Returns#

The method returns an object, whose keys are of the format {camel_case_data_model_name}_id, and their values are arrays of restored records' IDs.

For example, the returned object of the above example is:

Code
{
  "post_id": [
    "123",
    "321",
  ],
}

Restore Records Matching Filters#

Code
const restoredPosts = await postModuleService.restorePosts({
  name: "My Post",
})

Parameters#

To restore records matching a set of filters, pass an object of filters as a parameter to the method.

Note: Refer to the Filtering reference for more information on accepted filters and examples.

Returns#

The method returns an object, whose keys are of the format {camel_case_data_model_name}_id, and their values are arrays of restored records' IDs.

For example, the returned object of the above example is:

Code
{
  "post_id": [
    "123",
  ],
}
Was this page helpful?
Ask Bloom
For assistance in your development, use Claude Code Plugins or Docs MCP server in Cursor, VSCode, etc...FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break
⇧↵