Do I have to remove Parse Relation manually when Parent is deleted?

Do I have to remove Parse Relation manually when Parent is deleted?

// suppose we have a book object
var book = ...

// create a relation based on the authors key
var relation = book.relation("authors");

// generate a query based on that relation
var query = relation.query();

// now execute the query

And if I need to delete book from the db, how can I treat the author relation?
Or, is it removed automatically from the relation db?

Thank you.

It is not automatically deleted but there is no need for deleting them unless you want to save some database storage. In this case, you’d need to run another operation to delete them. An idea could be using a beforeDelete trigger.

Thanks to that, it became clear.

Hey, I would like to understand the behaviour a bit more to prevent building up any mess in the database

  1. Do I understand it right that the relation is saved in the child object then? Or it is an extra document class that is not visible through dashboard?

  2. How does it work then the other way around if I add/delete child? For example I have a parent book with many authors. And I have a liveQuery on that parent book. When there is a change in the child’s relations list (author added or removed), this then add/remove the relation together with the child itself as it is within the authors document? And how does the liveQuery reacts on that when the relations are not actually stored in the parent book object?

  3. Also as it is not within parent book document, am I correct that there is no writes per second limit (apart from hardware limitations)?

  • Do I understand it right that the relation is saved in the child object then? Or it is an extra document class that is not visible through dashboard?

It is an extra document

  • How does it work then the other way around if I add/delete child? For example I have a parent book with many authors. And I have a liveQuery on that parent book. When there is a change in the child’s relations list (author added or removed), this then add/remove the relation together with the child itself as it is within the authors document? And how does the liveQuery reacts on that when the relations are not actually stored in the parent book object?

Live query will not trigger for parent if the children in a relation are changed

  • Also as it is not within parent book document, am I correct that there is no writes per second limit (apart from hardware limitations)?

I didn’t get your question quite well. But the API supports multiple changes in the relation in a single api call.

1 Like