Bob Horn
Bob Horn

Reputation: 34297

RavenDB Disallow Delete if Not in Use

I just had a user delete two documents in my Raven DB. That caused issues as those documents were referenced by other documents. I know that Raven has a bundle to cascade delete, but I'm more looking for a way to disallow a delete if it's referenced by another document. Is there a standard RavenDB way of doing this? Or do I need to loop through all of my documents to check if the document is referenced?

Upvotes: 1

Views: 200

Answers (2)

Matt Warren
Matt Warren

Reputation: 10291

As Daniel said, RavenDB doesn't know about associatations between docs, so it can't do this out of the box.

However you could implement your own bundle and use the delete trigger functionality to veto/allow the delete to succeed.

If you want to go down this route, take a look at how the Cascading Delete bundle is implemented. You would just need to do the opposite.

Upvotes: 1

Daniel Lang
Daniel Lang

Reputation: 6839

Bob, unfortunately there's no standard way to do this, because the database itself doesn't know what a relation between documents is.

So, if you want to prevent user from deleting these documents then yes, you have to check yourself if there are any other documents referencing the current one.

Upvotes: 1

Related Questions