Delete all data associated with a thing, when the thing is deleted

I just learned that when I delete a thing via workflow, the data associated with that thing does get deleted from the database.

Eg. I have a Course thing, where each course has a list of lesson (another thing). Each lesson in turn saves a list of resources (type file). When a course is deleted, the data associated with it (lessons and their resources) are not deleted from the database (kinda stupid and weird), but how can I set up a workflow to delete everything when a course thing is deleted.

I understand their are no ‘for’ loops in bubble. How to achieve the above in the simplest way?

@emmanuel @keith @NigelG

This is actually handy because in some instances you don’t want to delete all the data associated with the deleted thing…without it you wouldn’t be able to use a data type as a field for relations because you’d end up deleting things you didn’t want to because they were related.

Also, I’ve set things up in projects before where the User is an employee and all of their data is owned by the employer who pays for the platform, so if the user is going to be deleted we don’t delete all of their data, we simply reassign it to a different employee.

There are loops. In backend workflow you can do ‘recursive workflows’ which loops. I also recently learned of a free plugin that does loops…can’t recall name but something like “looper”.

There are lots of ways to go about this, but would probably be in the backend workflows section. I just set this up tonight in an app of mine for a User deleting their account and needing to delete all data associated for another 6 types of data. Did all in backend. Some used action to delete list of things and I just did a search with constraints using my parameter key values set on the backend workflow. Others I did recursive backend workflows to loop through the list I sent.

2 Likes

Check out Backend Workflows as @boston85719 mentioned. Then create a DB Trigger on the Course thing. Try setting ‘Only when thing before is not empty and thing now is empty’ and put ‘Delete a list of things’ in this workflow.

1 Like

@codecompany @boston85719
Thanks a lot guys.
If it’s not too much trouble to ask, can you guys paste an example recursive workflow.

So many different ways to set them up that an example isn’t necessarily going to explain how to do it for your needs.

Search the forum for recursive workflows and maybe the Bubble reference to have a better idea of how to set them up.