Define connections between models in your semantic layer
relationships
key defines a list of connections from the current model to other models.related
) model.
Field | Required | Description |
---|---|---|
name | Yes | The name of the related semantic model this relationship connects to. |
source_col | Yes | The name of the join key column in the current model. |
ref_col | Yes | The name of the join key column in the related model. |
description | Yes | A human-readable description explaining the relationship’s business context. This is mandatory. |
type | No | Specifies the join type. Must be one of: LEFT , INNER , RIGHT , FULL OUTER . Defaults to LEFT if omitted. |
cardinality | No | Describes the numerical link between records. Must be one of: one-to-one , one-to-many , many-to-one , many-to-many . Optional. |
source_col
: Refers to the column in the current model’s underlying table/view that holds the key value. Often a foreign key.ref_col
: Refers to the column in the related model’s underlying table/view that holds the corresponding key value. Often a primary key.orders
model needs to link to a customers
model:
type
)LEFT
(Default): Includes all records from the current model (where the relationship is defined) and matching records from the related model. Fields from the related model will be NULL
if no match is found.INNER
: Includes only records where a match exists in both models based on the join keys.RIGHT
: Includes all records from the related model and matching records from the current model. Fields from the current model will be NULL
if no match is found. (Use with caution, often LEFT
from the other model is clearer).FULL OUTER
: Includes all records from both models. Fields will be NULL
where no match exists in the corresponding model.cardinality
)one-to-one
: Each record in the current model maps to at most one record in the related model, and vice-versa (e.g., users
to user_profiles
).one-to-many
: Each record in the current model can map to multiple records in the related model (e.g., customers
to orders
).many-to-one
: Multiple records in the current model can map to a single record in the related model (e.g., orders
to customers
). This is the inverse of one-to-many
.many-to-many
: Records in one model can map to multiple records in the other, and vice-versa (e.g., products
to orders
). This typically requires a junction model.one-to-many
relationship to the junction model. The junction model itself defines many-to-one
relationships back to each primary model.
Example: Products and Orders via order_items
Junction
relationship_name.field_name
.
Example: Cross-Model Metric Reference
source_col
and ref_col
correctly identify the join keys in the respective models. Mismatches lead to failed or incorrect joins.cardinality
and type
accurately based on the data’s structure and intended join logic. Defaults are convenient but should be verified.description
s explaining the business purpose of the relationship. This is crucial for understanding the model.orders -> customers
and customers -> orders
).