Skip to content

Delete Relation using condition

API request must identify the child objects to delete from the relation implicitely through a whereClause condition.

Method

Future<int> Backendless.data.of("TABLE-NAME"). deleteRelation(
                     String parentObjectId, 
                     String relationColumnName, 
                    {List<String> childrenObjectIds, 
                     String whereClause});
Future<int> Backendless.data.withClass<E>(). deleteRelation(
                    String parentObjectId, 
                    String relationColumnName, 
                   {List<String> childrenObjectIds, 
                    String whereClause});

where:

Argument                Description
TABLE-NAME Name of the table where the parent object is stored.
E Dart class of the parent object. The class name identifies the table where the parent object is stored.
parentObjectId The ID of an object for which the relation with the identified children will be deleted. When this argument is an instance of Map (for the map-based approach), it must contain the "objectId" property.
relationColumnName Name of the column representing the relation. Relationship between the child objects identified by whereClause will be deleted for this column in parentObject.
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.

Map parentObject = // parentObject retrieval is out of scope in this example

Backendless.data.of("Person"). deleteRelation(parentObject['objectId'], "user", 
  whereClause: 'name = "Joe" or name = "Frank"').then((response) {
    // relation has been deleted
});
Person personObject = // personObject retrieval is out of scope in this example

Backendless.data.withClass<Person>(). deleteRelation(personObject.objectId, "user", 
  whereClause: 'name = "Joe" or name = "Frank"').then((response) {
    // relation has been deleted
});