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

NameTypeRequiredDescription
objectNamestringYesName of the object from whose database table records are to be deleted
idstringNoID of a record to delete
filteranyNoFilter for records to delete, see :ref:`preside-objects-filtering-data` in :doc:`/devguides/presideobjects`
filterParamsstructNoFilter params for plain SQL filter, see :ref:`preside-objects-filtering-data` in :doc:`/devguides/presideobjects`
extraFiltersarrayNoAn array of extra sets of filters. Each array should contain a structure with :code:`filter` and optional `code:`filterParams` keys.
savedFiltersarrayNo
forceDeleteAllbooleanNo (default=false)If no id or filter supplied, this must be set to **true** in order for the delete to process
forceJoinsstringNo (default="")
fromVersionTablebooleanNo (default=false)
clearCachesbooleanNo (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
timeoutnumericNoTimeout, 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
);