deleteData()
Overview
public numeric function deleteData(
required string objectName
, string id
, any filter
, struct filterParams
, array extraFilters
, array savedFilters
, boolean forceDeleteAll = false
, string forceJoins = ""
, boolean fromVersionTable = false
, boolean clearCaches = Defaults to whether query caching is enabled or not for this object
, numeric timeout
)
Deletes records from the database. Returns the number of records deleted.
Arguments
Name | Type | Required | Description |
---|---|---|---|
objectName | string | Yes | Name of the object from whose database table records are to be deleted |
id | string | No | ID of a record to delete |
filter | any | No | Filter for records to delete, see :ref:`preside-objects-filtering-data` in :doc:`/devguides/presideobjects` |
filterParams | struct | No | Filter params for plain SQL filter, see :ref:`preside-objects-filtering-data` in :doc:`/devguides/presideobjects` |
extraFilters | array | No | An array of extra sets of filters. Each array should contain a structure with :code:`filter` and optional `code:`filterParams` keys. |
savedFilters | array | No | |
forceDeleteAll | boolean | No (default=false) | If no id or filter supplied, this must be set to **true** in order for the delete to process |
forceJoins | string | No (default="") | |
fromVersionTable | boolean | No (default=false) | |
clearCaches | boolean | No (default=Defaults to whether query caching is enabled or not for this object) | Whether or not to clear caches related to the object whose record you are deleting |
timeout | numeric | No | Timeout, in seconds, of the main delete DB query |
Examples
// delete a single record
deleted = presideObjectService.deleteData(
objectName = "event"
, id = rc.id
);
// delete multiple records using a filter
// (note we are filtering on a column in a related object, "category")
deleted = presideObjectService.deleteData(
objectName = "event"
, filter = "category.label != :category.label"
, filterParams = { "category.label" = "BBQs" }
);
// delete all records
// (note we are filtering on a column in a related object, "category")
deleted = presideObjectService.deleteData(
objectName = "event"
, forceDeleteAll = true
);