Delete related children


If I have Table A that has 1:N relation to Table B

Is there a way that I can delete all the objects in Table B that are related to certain object in Table A

The way I can think of it is cumborsome:
1- Get all the related rows from Table B by quering the relation on Table !
2- Delete the rows from Table B
3- Delete the relation from Table A

Is there a shorter way where I can say:

Delete all the rows in Table B whose parent in Table A has object id xyz

Delete the relation and its rows from Table A where object is xyz

Thank you

1 Like

Hi SnakeEyes,

Yes, there is exactly such a request - a bulk delete on table B with where clause “A[relationToB].objectId=‘xyz’”. As soon as the related object(s) is deleted, the relation is also removed - you don’t have to break it manually if one of the objects disappears.
Here’s a relevant doc on bulk delete:
Though apparently it’s only available via REST now.

Hello , any update on my query above?Thank you!

Thank you. I am using android sdk for my android app. Is this not availble there?

Yes, there is (not documented yet though):

Backendless.Data.remove( “tableName”, “whereClause” )

Thanks Mark and Sergey. I am just not sure how the syntax would be done in the use case. I can see based on the syntax of Backendless.Data.remove( “tableName”, “whereClause” ) that the where clause will apply on columns on the TableName (such as amount >0, text = “John” …etc). But what don’t see how it can be used on another table relating to the table in question. Let’s use real column name to illustrate.

Suppose we have 2 tables. Person and Address.
Person table has column “addresses” which is 1:N to the table Address.

I want to delete all the addresses for the person with ObjectId= “AAAA-BBBB-1”

How can this be achieved using the remove method?
Thank you

In that case, the API call would look like this:

Backendless.Data.remove( “Address”, “Person[addresses].objectId = 'AAAA-BBBB-1” )

Thank you. Btw the api I found was

Backendless.Data.of(String table).remove(string where)I tried it and it worked

can you provide a code example?
I’ve tried
await Backendless.Data.of(“Address”).remove(“Address” "Person[addresses].objectId =’ “+ Person.objectId+” ’ ");
it doesn’t seems to work

You are using wrong single quote. It should be this:

not this:

See the example from the documentation: