Skip to content

Delete Relation using condition

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

Blocking API

Integer result = Backendless.Persistence.of( "TABLE-NAME" ).deleteRelation( 
                                                   Map parentObject,
                                                   String relationColumnName,
                                                   String whereClause );
Integer result = Backendless.Persistence.of( E ).deleteRelation( 
                                                   E parentObject,
                                                   String relationColumnName,
                                                   String whereClause );

Non-Blocking API

Backendless.Persistence.of( "TABLE-NAME" ).deleteRelation( 
                                             Map parentObject,
                                             String relationColumnName,
                                             String whereClause,
                                             AsyncCallback<Integer> callback );
Backendless.Persistence.of( E ).deleteRelation( 
                                   E parentObject,
                                   String relationColumnName,
                                   String whereClause,
                                   AsyncCallback;<Integer> callback );

where:

Argument                Description
TABLE-NAME Name of the table where the parent object is stored.
E Java 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 identified children will be deleted. When this argument is an instance of java.util.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.
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 removed from the relationship. The asynchronous call receives the return value through a callback executed on the AsyncCallback object.

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.

HashMap<String, Object> parentObject = new HashMap<String, Object>();
parentObject.put( "objectId", "41230622-DC4D-204F-FF5A-F893A0324800" );

Backendless.Data.of( "Person" ).deleteRelation( parentObject, 
                                                "user", 
                                                "name = \"Joe\" or name = \"Frank\"", 
                                                new AsyncCallback<Void>()
{
  @Override
  public void handleResponse( Void response )
  {
    Log.i( "MYAPP", "relation has been deleted" );
  }

  @Override
  public void handleFault( BackendlessFault fault )
  {
    Log.e( "MYAPP", "server reported an error - " + fault.getMessage() );
  }
} );
Person personObject = // personObject retrieval is out of scope in this example

Backendless.Data.of( Person.class ).deleteRelation( personObject, 
                                                    "user", 
                                                    "name = \"Joe\" or name = \"Frank\"",
        new AsyncCallback<Integer>()
        {
          @Override
          public void handleResponse( Integer response )
          {
            Log.i( "MYAPP", "relation has been deleted");
          }

          @Override
          public void handleFault( BackendlessFault fault )
          {
            Log.e( "MYAPP", "server reported an error - " + fault.getMessage() );
          }
        } );