Skip to content

Delete Objects from relation

The API removes specific objects from a relationship with their parent.

Backendless.Data.of( "TABLE-NAME" ).deleteRelation( 
      parentObject,
      relationColumnName,
      childrenArray )
  .then( function( count ) {
   })
  .catch( function( error ) {
   });
Backendless.Data.of( DataTypeX ).deleteRelation( 
       parentObject,
       relationColumnName,
       childrenArray )
 .then( function( count ) {
  })
 .catch( function( error ) {
  });

where:

Argument                Description
TABLE-NAME name of the table where the parent object is stored.
DataTypeX reference to a JS function/class identifying the table. Name of the table must match the name of the function.
parentObject The object for which the relation with the specified children will be deleted. When this argument is a plain  JS object (for the "Untyped Objects" approach), it must contain the "objectId" property.
relationColumnName name of the column identifying the relation. Relation between the parent object and the objects from the childrenArray array for the  column in parentObject will be deleted.
childrenArray an array of child objects for which the relation with parentObject will be deleted.

Return Value

Number of child objects for which the relationship has been deleted.

Example

The example below deletes a relation between an object from the Person table and its children. The child objects are referenced explicitly in the API call (see the object IDs in the collection as "XXXXX-XXXXX-XXXXX-XXXXX" and "ZZZZ-ZZZZ-ZZZZZ-ZZZZZ"``).The relation column is address.

var parentObject = { objectId:"41230622-DC4D-204F-FF5A-F893A0324800"};
var childObject1 = { objectId:"XXXX-XXXX-XXXX-XXXXX" };
var childObject2 = { objectId:"ZZZZ-ZZZZ-ZZZZZ-ZZZZZ" };
var children = [ childObject1, childObject2 ];

Backendless.Data.of( "Person" ).deleteRelation( parentObject, "address", children )
 .then( function( count ) {
    console.log( "relation has been deleted" );
  })
 .catch( function( error ) {
    console.log( "server reported an error - " + error.message );
  });
function Person {
  // properties of Person defined here
}

function Address {
  // properties of Address defined here
}

var personObject = // personObject retrieval is out of scope in this example
var addressObject1 = // addressObject retrieval is out of scope in this example
var addressObject2 = // addressObject retrieval is out of scope in this example
var addressCollection = [ addressObject1, addressObject2 ];

Backendless.Data.of( Person ).deleteRelation( personObject, "address", addressCollection )
  .then( function( count ) {
     console.log( "relation has been deleted");
   })
  .catch( function( error ) {
     console.log( "server reported an error - " + error.message );
   });