Skip to content

Delete Relation using condition

The API deletes objects from a relationship with their parent. The objects are identified implicitly through a whereClause condition.

Backendless.Data.of( "TABLE-NAME" ).deleteRelation( 
     parentObject,
     relationColumnName,
     whereClause )
  .then( function( count ) {
   })
  .catch( function( error ) {
   });
Backendless.Data.of( DataTypeX ).deleteRelation( 
     parentObject,
     relationColumnName,
     whereClause )
  .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 representing the relation. Relation between the parent object and the objects identified  through whereClause for the  column in parentObject will be deleted.
whereClause A where clause condition identifying the objects in the child table which will be removed from the relation to the parent object.

Return Value

Number of child objects removed from the relationship.

Example

The following request deletes a relation between a Person object and all the related objects in the related table identified by column "user" which match the provided query:

name='Joe' or name = 'Frank' 

As a result of the operation, all related objects where the name property is either Joe or Frank will be deleted from the relation.

var parentObject = { objectId:"41230622-DC4D-204F-FF5A-F893A0324800" };

Backendless.Data.of( "Person" ).deleteRelation( parentObject, 
                                                "user", 
                                                "name = \"Joe\" or name = \"Frank\"" )
 .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
}

var parentObject = // retrieval of the parent object is out of scope of the example

Backendless.Data.of( Person ).deleteRelation( parentObject, 
                                                "user", 
                                                "name = \"Joe\" or name = \"Frank\"" )
 .then( function( count ) {
    console.log( "relation has been deleted" );
  })
 .catch( function( error ) {
    console.log( "server reported an error - " + error.message );
  });