Skip to content

Delete Objects from relation

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

- (void)deleteRelationWithColumnName:(NSString * _Nonnull)columnName parentObjectId:(NSString * _Nonnull)parentObjectId childrenObjectIds:(NSArray<NSString *> * _Nonnull)childrenObjectIds responseHandler:^(NSNumber * _Nonnull)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;
func deleteRelation(columnName: String, parentObjectId: String, childrenObjectIds: [String], responseHandler: ((NSNumber) -> Void)!, errorHandler: ((Fault) -> Void)!)

- (void)deleteRelationWithColumnName:(NSString * _Nonnull)columnName parentObjectId:(NSString * _Nonnull)parentObjectId childrenObjectIds:(NSArray<NSString *> * _Nonnull)childrenObjectIds responseHandler:^(NSNumber * _Nonnull)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;
func deleteRelation(columnName: String, parentObjectId: String, childrenObjectIds: [String], responseHandler: ((NSNumber) -> Void)!, errorHandler: ((Fault) -> Void)!)

where:

Argument                Description
parentObjectId -must be objectId of the object which contains specified related child objects.
columnName Name of the column identifying the relation. Relationship between the specified objects from the children collection will be deleted for the column in the table containing parentObjectId.
childrenObjectIds A collection of child objectId values for which the relationship with parentObjectId will be deleted.

Return Value

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

Example

The example below deletes a relation between a Person object and its children (the relation column is address). The child objects are referenced explicitly in the API call.

DataStoreFactory *dataStore = [Backendless.shared.data of:[Person class]];
[dataStore deleteRelationWithColumnName:@"address" parentObjectId:@"XXXXX" childrenObjectIds:@[@"YYYYY"] responseHandler:^(NSNumber *relations) {
    NSLog(@"Relation has been removed");
} errorHandler:^(Fault *fault) {
    NSLog(@"Error: %@", fault.message);
}];
let dataStore = Backendless.shared.data.of(Person.self)
dataStore.deleteRelation(columnName: "address", parentObjectId: "XXXXX", childrenObjectIds: ["YYYYY"], responseHandler: { relations in
    print("Relation has been removed")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})

MapDrivenDataStore *dataStore = [Backendless.shared.data ofTable:@"Person"];
[dataStore deleteRelationWithColumnName:@"address" parentObjectId:@"XXXXX" childrenObjectIds:@[@"YYYYY"] responseHandler:^(NSNumber *relations) {
    NSLog(@"Relation has been removed");
} errorHandler:^(Fault *fault) {
    NSLog(@"Error: %@", fault.message);
}];
let dataStore = Backendless.shared.data.ofTable("Person")
dataStore.deleteRelation(columnName: "address", parentObjectId: "XXXXX", childrenObjectIds: ["YYYYY"], responseHandler: { relations in
    print("Relation has been removed")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})