Domanda

I am new to Raven DB and new to the concept of No SQL DBs. I am trying to shed some of the concepts that come with RDBs. Once concept is that if a record is being used as a foreign key somewhere, an RDB won't let me delete the master record.

Suppose I wan't to delete a Category and that category's ID is being used in some Product then a RDB won't let me delete that record. This is quite helpful as I don't have to worry about accidently deleting the record. How can I apply the same concept to Raven DB? I want to use normalized structure like RDBs because I plan to use Raven DB in conjunction with some RDB. I want to be on the safe side just in case so that I don't end up in a situation where I have chaos due to experimenting with a new concept.

Hope I made sense,

Any help will be extremely appreciated!

È stato utile?

Soluzione

There is no such concept as a foreign key constraint in RavenDB. Really, there is no foreign key. All you have in your document is a string that can be used to go fetch another document. We call that a relationship, but it is a loose term. There is nothing going on under the hood to link those documents together and prevent you from doing that delete.

In the scenario you described, you would still be able to load the product. But you would get a null if you tried to load the category using that product's category id.

You have to maintain these relationships yourself. The only helper available is the Cascade Delete Bundle - but you still must wire up each entity for cascading. It doesn't do it automatically like it would with a sql foreign key based cascade delete.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top