How to: Delete a thing
Last updated
Last updated
To delete a thing we need to be able to target it correctly. The Delete a thing action actually works for multiple things, so based on the filter you setup it will target one of more entries to delete.
Here we have try to delete a post based on Unique ID, so we target it with the filter. This way, since the Unique ID is by definition is unique it will target this single entry.
Let's look at a different scenario:
Now in this example we target the Title, which is not unique and can be multiple entries of the same name. The action will delete all of those
Please double check you always target the relevant things.
Note on Cascade delete: You can setup your Database to delete entries when a referenced field is being deleted.
As previously mentioned and shown in examples, we can setup a Database structure where a table called "post" has a foreign key relation to "Category" table. Which means we can reference and filter based on each other and do some complex things.
However let's say when you remove a "Category" you'd like to remove all the "post" related. In this case we don't have to setup complex workflows to remove all those rows we can let Supabase remove them for us automatically.
This is mostly useful when you have a very interconnected system, and maybe you'd like to remove everything which the "User" have been attached, all you need to remove is the "User" after that everything else will happen like a waterfall and all records will be deleted which references that "User"