Back to Medusa

{metadata.title}

www/apps/resources/app/service-factory-reference/methods/soft-delete/page.mdx

2.14.21.9 KB
Original Source

export const metadata = { title: softDelete Method - Service Factory Reference, }

{metadata.title}

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

ts
const deletedPosts = await postModuleService.softDeletePosts(
  "123"
)

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:

json
{
  "post_id": ["123"]
}

Soft Delete Multiple Records

ts
const deletedPosts = await postModuleService.softDeletePosts([
  "123",
  "321",
])

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:

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

Soft Delete Records Matching Filters

ts
const deletedPosts = await postModuleService.softDeletePosts({
  name: "My Post",
})

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.

</Note>

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:

json
{
  "post_id": ["123"]
}