Delete relation data

Hi - sorry for all the questions (here and Slack).

When I delete a parent object I want to delete all the child relation data in a logic block - any ideas how I can do that.

Thanks
Pat

Hi,

You can delete the child objects first using the bulk delete API. There would be one where clause query which identifies all child objects of a specific parent. Do you need help with composing the query?

Regards,
Mark

Thanks Mark - let me have a play first, learn by doing and all that!

I’m so used to the concept of FKs - I can’t see how I put the where clause together as my child table doesn’t store the id of the parent.

I just linked the child to the parent with add relation, should I be storing the parent id in the child object?

This should help:
https://backendless.com/docs/rest/data_inverted_relation_retrieval.html

Let me know if it gets too confusing, I’ll walk you though.

Cheers,
Mark

I’m sorry Mark - I’m just not getting this. I suppose my mind is still stuck in the world of joins and RDBMS where this is very straightforward- been doing that for 30 years and new to this way of working.

No problem. Please provide more info:

  1. What are the names of your tables? Parent, child?
  2. Where is the relation column is declared? In what table that is?
  3. What is the name of the relation column?

Thanks,
Mark

InventoryItem is the parent table
InventoryImages is the child table

ItemImages is the relation column in the parent table - one to many to the child table

To get all images which belong to a specific parent you can use the following where clause. The query must be sent to the InventoryImages table:

InventoryItem[ItemImages].objectId = 'OBJECTID-VALUE-OF-SPECIFIC-PARENT'

Hope this helps.

Mark

Do you know how to test the query in Backendless console?

no…

See this: https://backendless.com/how-to-use-backendless-rest-console-to-fetch-your-data/
The Where field is where you put your where clause. The GET button will execute find requests.

Well thats damned handy! Thanks, got it working now. Ran into another thing but will raise another thread about it…