Temporal Relationships
Relationships are one of the more difficult aspects of working with temporal data. This is because there is context implied with the relationship itself. One must be aware of the context in order to set up the appropriate relationship.
#####Wait - RavenDB isn't a relational database, is it?
That's correct. RavenDB is not a relational database in the traditional sense, but that does not mean that you cannot express objects that have a relationship. For example, an Order and a Customer certainly have a relationship, and they would be usually expressed in two separate documents. This could be represented with a CustomerId
in the order, or an OrderIds
list in the customer, or possibly both. You can read all about relationships in RavenDB in the documentation.
RavenDB 2.0 introduced a new feature that makes working with relationships during indexing very easy, using LoadDocument
. You can read more about indexing related documents in the documentation, or on Ayende's blog. In addition to its original purposes, we can also use this feature to express temporal relationships.
Due to the complexities of temporal contexts, there are 10 (yes, ten) ways you can can relate two entities together.
We'll define the following abbreviations:
-
Nt = Non Temporal
A regular entity, not tracked with temporal versioning. -
Tc = Temporal Current
The current version of a temporal entity. The one effective now. -
Tx = Temporal Correlated
The version of a temporal entity that is effective at some specific date, which comes from the related document. -
Tr = Temporal Range
Any particular revision of a temporal entity, effective over a range between start and until dates.
Let's call the document we are indexing the source document. Then we'll call the document we are relating to (using LoadDocument
) the target document. Now we have a convenient shorthand for expressing the temporal relationship types, as source:target
.
Using this notation, the 10 types of relationships are as follows:
(click for examples and details of each)
All of these can be defined in the index with creative use of LoadDocument
, temporal metadata, and the temporal history document. However, Tr:Tr
relationships are the most complex, and require additional work in the query itself.
Introduction
Home
About Temporal Versioning
About DateTimeOffset
Setup
Installation
Enabling The Bundle
Client Initialization
Configuration
Migration
Usage
Specifying Effective Dates
Basic CRUD Operations
Temporal Activation
Querying Temporal Data
Querying Dynamically
Querying a Static Index
Map/Reduce of Current Data
Advanced
Temporal Map/Reduce
Temporal Relationships
Guidance
Getting an Audit Trail
Practical Application Guidance
Reference
Misc