3.2. Relationships
Relationships between nodes are a key part of a graph database. They allow for finding related data. Just like nodes, relationships can have properties.
A relationship connects two nodes, and is guaranteed to have valid start and end nodes.
As relationships are always directed, they can be viewed as outgoing or incoming relative to a node, which is useful when traversing the graph:
Relationships are equally well traversed in either direction. This means that there is no need to add duplicate relationships in the opposite direction (with regard to traversal or performance).
While relationships always have a direction, you can ignore the direction where it is not useful in your application.
Note that a node can have relationships to itself as well:
To further enhance graph traversal all relationships have a relationship type. Note that the word type might be misleading here, you could rather think of it as a label. The following example shows a simple social network with two relationship types.
Using relationship direction and type
What | How |
---|---|
get who a person follows | outgoing |
get the followers of a person | incoming |
get who a person blocks | outgoing |
get who a person is blocked by | incoming |