softDelete Method - Service Factory Reference

This method of a module's service soft deletes one or more records of a data model.

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

Soft Delete One Record#

Code
1const deletedPosts = await postModuleService.softDeletePosts(2  "123"3)

Parameters#

To soft delete a 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 soft-deleted records' IDs.

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

Code
1{2  "post_id": ["123"]3}

Soft Delete Multiple Records#

Code
1const deletedPosts = await postModuleService.softDeletePosts([2  "123",3  "321",4])

Parameters#

To soft delete 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 soft-deleted records' IDs.

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

Code
1{2  "post_id": [3    "123",4    "321"5  ]6}

Soft Delete Records Matching Filters#

Code
1const deletedPosts = await postModuleService.softDeletePosts({2  name: "My Post",3})

Parameters#

To soft delete 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 soft-deleted records' IDs.

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

Code
1{2  "post_id": ["123"]3}
Was this page helpful?
Ask Anything
Ask any questions about Medusa. Get help with your development.
You can also use the Medusa 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