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
OR
Delete the relation and its rows from Table A where object is xyz
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: https://backendless.com/docs/rest/doc.html#deletingseveralobjectsatatimebulkdelete
Though apparently itâs only available via REST now.
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
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