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 ?? "")")
})
Codeless Reference¶
where:
Argument | Description |
---|---|
table name |
Name of the table where which contains the parent object as identified by parent object . |
parent object |
Id of the object for which the relation will be deleted. |
relation name |
Name of the column which identifies the relation within the parent table (identified as table name ). |
children |
You must use the where clause condition in this property to delete specific children objects from the data table. |
return result |
When this box is checked, the operation returns the number of removed child objects relations. |
Returns the number of removed child objects relations.
Consider the first object with one-to-many relations(skills
column) in the parent data table called employees
:
By clicking the record (1:N Relations
) in the skills
column of the parent data table presented above, you get redirected to the child data table called uniqueSkills
, where you can see the related children objects:
Suppose, you want to delete only one relation. The example below deletes the Objective-C
relation from the data table using the where clause condition "skill = 'Objective-C'"
specified in the children
property:
The result of this operation is one deleted relation Objective-C
from the data table:
In case you want to delete multiple objects relations using the where clause condition, refer to the example below which removes all relations except the Java
.
After the Codeless Logic runs, only one object relation Java
remains in the data table.