Relationship Spec
Define model associations using hasOne, hasMany, belongsTo, and more.
The relationships section in a Model Spec defines how your model is connected to other models. These associations power expansions, filtering across models, and relational dropdowns in forms.
Relationships are declared explicitly and support standard types like:
has_onehas_manybelongs_to
🔧 Basic Structure
🧭 Relationship Types
🧩 has_many
Represents a one-to-many relationship.
- This means: A user has many posts.
foreignKeyis on the child (post.user_uuid)localKeyis on the parent (user.uuid)
🧩 has_one
Represents a one-to-one relationship.
Same structure as
has_many, but for singular relation.
🧲 belongs_to
Represents an inverse relationship, where the current model belongs to another.
foreignKeyis on the current model (user.role_id)ownerKeyis on the related model (role.uuid)
🧠 Why Explicit Relationships?
- They enable
expandfunctionality in Views and Entities - They power related dropdowns in forms (like selecting a city for a user)
- They allow building cross-model filters and queries
- They define directional joins for internal engine resolution
🧪 Example: Complete Relationship Block
🔎 Where Relationships Are Used
- expand in View & Entity Specs
- Mutators for dynamic dropdowns and contextual forms
- Select/Filters for deep querying across models
- Generators (e.g. referencing related values or backfilling)