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.

- (void)deleteRelationWithColumnName:(NSString * _Nonnull)columnName parentObjectId:(NSString * _Nonnull)parentObjectId whereClause:(NSString * _Nullable)whereClause responseHandler:^(NSNumber * _Nonnull)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;
func deleteRelation(columnName: String, parentObjectId: String, whereClause: String?, responseHandler: ((NSNumber) -> Void)!, errorHandler: ((Fault) -> Void)!)

- (void)deleteRelationWithColumnName:(NSString * _Nonnull)columnName parentObjectId:(NSString * _Nonnull)parentObjectId whereClause:(NSString * _Nullable)whereClause responseHandler:^(NSNumber * _Nonnull)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;
func deleteRelation(columnName: String, parentObjectId: String, whereClause: String?, responseHandler: ((NSNumber) -> Void)!, errorHandler: ((Fault) -> Void)!)

where:

Argument                Description
parentObjectId must be objectId of the object which contains related children identified by columnName.
columnName Name of the column identifying the relation. Relationship between the child objects identified by whereClause will be deleted for this column in the table containing parentObjectId.
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.

DataStoreFactory *dataStore = [Backendless.shared.data of:[Person class]];
[dataStore deleteRelationWithColumnName:@"users" parentObjectId:@"XXXXX" whereClause:@"name='Joe' OR name = 'Frank'" responseHandler:^(NSNumber *relations) {
    NSLog(@"%@ relations have been removed", relations);
} errorHandler:^(Fault *fault) {
    NSLog(@"Error: %@", fault.message);
}];
let dataStore = Backendless.shared.data.of(Person.self)
dataStore.deleteRelation(columnName: "users", parentObjectId: "XXXXX", whereClause: "name='Joe' OR name = 'Frank'", responseHandler: { relations in
    print("\(relations) relations have been removed")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})

MapDrivenDataStore *dataStore = [Backendless.shared.data ofTable:@"Person"];
[dataStore deleteRelationWithColumnName:@"users" parentObjectId:@"XXXXX" whereClause:@"name='Joe' OR name = 'Frank'" responseHandler:^(NSNumber *relations) {
    NSLog(@"%@ relations have been removed", relations);
} errorHandler:^(Fault *fault) {
    NSLog(@"Error: %@", fault.message);
}];
let dataStore = Backendless.shared.data.ofTable("Person")
dataStore.deleteRelation(columnName: "users", parentObjectId: "XXXXX", whereClause: "name='Joe' OR name = 'Frank'", responseHandler: { relations in
    print("\(relations) relations have been removed")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})