Databases Reference
In-Depth Information
Sometimes, however, we have a closed set of relationships, but in some traversals we
want to follow specific kinds of relationships within that set, whereas in others we want
to follow all of them, irrespective of type. Addresses are a good example. Following the
closed-set principle, we might choose to create HOME_ADDRESS , WORK_ADDRESS , and DE
LIVERY_ADDRESS relationships. This allows us to follow specific kinds of address rela‐
tionships ( DELIVERY_ADDRESS , for example) while ignoring all the rest. But what do we
do if we want to find all addresses for a user? There are a couple of options here. First,
we can encode knowledge of all the different relationship types in our queries: e.g.,
MATCH user-[:HOME_ADDRESS|WORK_ADDRESS|DELIVERY_ADDRESS]->address . This,
however, quickly becomes unwieldy when there are lots of different kinds of relation‐
ships. Alternatively, we can add a more generic ADDRESS relationship to our model, in
addition to the fine-grained relationships. Every node representing an address is then
connected to a user using two relationships: a fined-grained relationship (e.g., DELIV
ERY_ADDRESS ) and the more generic ADDRESS {type: 'delivery'} relationship.
As we discussed in “Describe the Model in Terms of the Application's Needs” on page
63 , the key here is to let the questions we want to ask of our data guide the kinds of
relationships we introduce into the model.
Model Facts as Nodes
When two or more domain entities interact for a period of time, a fact emerges. We
represent these facts as separate nodes, with connections to each of the entities engaged
in that fact. Modeling an action in terms of its product—that is, in terms of the thing
that results from the action—produces a similar structure: an intermediate node that
represents the outcome of an interaction between two or more entities. We can use
timestamp properties on this intermediate node to represent start and end times.
The following examples show how we might model facts and actions using intermediate
nodes.
Employment
Figure 4-2 shows how the fact of Ian being employed by Neo Technology in the role of
engineer can be represented in the graph.
Search WWH ::




Custom Search