Delete Objects from relation¶
The API removes specific objects from a relationship with their parent.
Blocking API¶
int result = Backendless.Data.Of( "TABLE-NAME" ).DeleteRelation( Dictionary<string, object> parentObject, string relationColumnName, object[] children );
int result = Backendless.Data.Of<E>().DeleteRelation( E parentObject, string relationColumnName, object[] children );
Non-Blocking API¶
Backendless.Data.Of( "TABLE-NAME" ).DeleteRelation( Dictionary<string, object> parentObject, string relationColumnName, object[] children, AsyncCallback<int> callback );
Backendless.Data.Of<E>().DeleteRelation( E parentObject, string relationColumnName, object[] children, AsyncCallback;<int> callback );
where:
Argument | Description |
---|---|
TABLE-NAME |
Name of the table where the parent object is stored. |
E |
.NET class of the parent object. The class name identifies the table where the parent object is stored. |
parentObject |
The object for which the relation with the specified children will be deleted. When this argument is an instance of Dictionary<string, object> (for the dictionary-based approach), it must contain the "objectId" property. |
relationColumnName |
Name of the column identifying the relation. Relationship between the specified objects from the children collection will be deleted for the column in parentObject . |
children |
An array of child objects for which the relationship with the parentObject will be deleted. Each object must have a valid value for the objectId property. |
callback |
a responder object which will receive a callback when the relation has been deleted or if an error occurs. Applies to the asynchronous method only. |
Return Value¶
Number of child objects for which the relationship has been deleted. The asynchronous call receives the return value through a callback executed on the AsyncCallback
object.
Example¶
The example below deletes a relation between a Person
object and its children. The child objects are referenced explicitly in the API call.
The relation column is address
.
Dictionary<string, object> parentObject = new Dictionary<string, object>(); parentObject[ "objectId" ] = "41230622-DC4D-204F-FF5A-F893A0324800"; Dictionary<string, object> childObject1 = new Dictionary<string, object>(); childObject1[ "objectId" ] = "XXXX-XXXX-XXXX-XXXXX"; Dictionary<string, object> childObject2 = new Dictionary<string, object>(); childObject2[ "objectId" ] = "ZZZZ-ZZZZ-ZZZZZ-ZZZZZ"; object[] children = new object[] { childObject1, childObject2 }; AsyncCallback<int> deleteRelationCallback = new AsyncCallback<int>( howMany => { System.Console.WriteLine( String.Format( "Server has removed {0} objects from the relation", howMany ) ); }, error => { System.Console.WriteLine( "Server returned an error " + error.Message ); } ); Backendless.Data.Of( "Person" ).DeleteRelation( parentObject, "address", children, deleteRelationCallback );
Person personObject = // personObject retrieval is out of scope in this example Address addressObject1 = // addressObject retrieval is out of scope in this example Address addressObject2 = // addressObject retrieval is out of scope in this example object[] childObjects = new object[] { addressObject1, addressObject2 }; AsyncCallback<int> deleteRelationCallback = new AsyncCallback<int>( howMany => { System.Console.WriteLine( String.Format( "Server has removed {0} objects from the relation", howMany ) ); }, error => { System.Console.WriteLine( "Server returned an error " + error.Message ); } ); Backendless.Data.Of<Person>().DeleteRelation( personObject, "address", childObjects, deleteRelationCallback );