Cascade Delete

Hey folks, let’s say I have a database for a blog, and each blog post has a “categories” field where a category is a collection so the value of this field is a reference.

The issue is, a category can be deleted/removed at any time leaving a “ghost” reference in the blog post data. What is the recommended way to deal with those scenarios using Fauna? In SQL, you can have a CASCADE DELETE for example.

In the past, I had a query to:

  • Delete the document
  • Search for the blog posts using that category
  • Remove the category from the blog posts

I’m wondering if there is an easy way these days, especially using FLQ 10.

Thanks in advance!

In FQL v10, the schema can enable referential integrity. We are still working on launching user-defined schema, but you can see this at work already, for example where Roles reference Collections: You cannot delete a Collection without also removing that Collection from the Role.

The step after that is to have an API for cascading deletes, but that will not be available in the near term.

Your process for removing related documents is still the way to go with FQL v10. We’ve updated our support article regarding cascading deletes to v10 recently.

1 Like

Hi @BrunoQuaresma we do plan to enforce referential integrity in when we implement schema enforcement, but we have no plans to provide cascading deletes. Referential integrity would be enforced in the following way

  • Write operations fail with an error if the deleted document exists as a non-null parent reference in any other child document
  • A parent document can be deleted if all child documents are also deleted the same transaction
1 Like

Great! This would be good enough for my case.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.