Skip to main content
Version: Next

Relationship Types

A RelationshipType defines a typed, directional connection between entities. Because relationships are themselves entities (of type entity_type/relationship_type), they can carry their own properties (edge properties) and participate in further relationships.

Defining a RelationshipType

Properties

FieldTypeRequiredDescription
namestringyesSystem identifier; used as the key
labellocalized mapyesDisplay name per locale
descriptionlocalized mapnoDescription per locale
iconstringnoIcon identifier for UI display
target_typeentity referenceyesConstrains the entity type of the target
key_scriptLua stringnoComputes keys for relationship instances. See Lua Scripting.
label_scriptLua stringnoComputes labels for relationship instances. See Lua Scripting.

Relationships on a RelationshipType

RelationshipTarget TypeDescription
has_propproperty_typeEdge properties carried by each relationship instance
has_relrelationship_typeFurther relationships that relationship instances can participate in

Example

{
"key": "has_ingredient",
"properties": {
"name": "has_ingredient",
"label": { "en_us": "Has Ingredient", "de_de": "Hat Zutat" },
"target_type": "entity_type/vegetable"
},
"relationships": {
"has_prop": [
{
"properties": { "name": "quantity", "label": { "en_us": "Quantity" }, "required": true },
"target": "int_property_type/generic"
},
{
"properties": { "name": "unit", "label": { "en_us": "Unit" } },
"target": "string_property_type/generic"
}
]
}
}

This defines a has_ingredient relationship type that targets vegetable entities and carries quantity and unit as edge properties.

Relationship Instances

A relationship instance represents a concrete connection between two entities. It is itself a full entity with its own UUID, properties, and metadata.

Fields

FieldDescription
sourceUUID of the entity that owns this relationship
targetUUID of the entity being pointed to
propertiesEdge property values defined by the relationship type's has_prop

Creating Relationship Instances

Relationships can be created inline when creating or updating an entity:

{
"key": "lasagna",
"properties": { "name": { "en_us": "Lasagna" } },
"relationships": {
"has_ingredient": [
{
"target": "vegetable/tomato",
"properties": { "quantity": 3, "unit": "pieces" }
},
{
"target": "vegetable/onion",
"properties": { "quantity": 1, "unit": "pieces" }
}
]
}
}

They can also be created through the dedicated relationship routes:

POST /api/v1/by-key/recipe/lasagna/relationships/has_ingredient

See REST API Reference for the full relationship route documentation.

Relationship Keys and Sub Key Spaces

Relationship instances have their own key, computed by the key_script on the RelationshipType (following the same resolution precedence as entity keys).

Key uniqueness is scoped to a sub key space for the combination of (relationship_type, source_entity). Two relationship instances of the same type may share a key as long as they have different source entities.

Canonical Reference Format

The canonical reference for a relationship instance follows the form:

source_entity_type/source_entity_key/relationship_type/relationship_key

For example: recipe/lasagna/has_ingredient/tomato

Relationship instances also carry their own root_id and id, with the same versioning semantics as regular entities.

Declaring Relationships on Entity Types

Entity types declare which relationship types they participate in via has_rel:

"has_rel": [
{
"properties": { "name": "has_ingredient", "label": { "en_us": "Ingredients" } },
"target": "relationship_type/has_ingredient"
}
]

The target points to the RelationshipType entity. Only relationship types declared via has_rel can be used on instances of that entity type.

Built-in System Relationship Types

These are defined by the system and used to describe the meta model itself:

NameTargetDescription
has_propproperty_typeDeclares a property on an entity type or relationship type
has_virtual_propproperty_typeDeclares a computed property
has_relrelationship_typeDeclares a relationship on an entity type or relationship type
has_listentity_typeDeclares a list on an entity type
has_parententity_typeInheritance link
has_lc_maplc_mapLinks an entity type to a lifecycle map
has_lc_statuslc_statusLinks a lifecycle map to its statuses
has_lc_transitionlc_statusDefines a valid transition from one lc_status to another
has_actionactionDeclares an action on an entity type
has_hookactionDeclares a hook on an entity type
info

System relationship types are part of the meta model and cannot be modified by customers. They form the foundation on which all data modeling is built.

Traversing Relationships via the API

The API provides several ways to navigate relationships:

RouteDescription
GET /@outgoingAll outgoing relationships, keyed by relationship type UUID
GET /@incomingAll relationship entities whose target points to this entity
GET /@referenced-byAll entities that hold a relationship pointing at this entity
GET /relationshipsAll relationships grouped by relationship type name
GET /relationships/<rel_name>All instances of a specific relationship type
GET /relationships/<rel_name>/<rel_root_id>/@targetNavigate through a relationship to the target entity

See REST API Reference for the complete traversal documentation.