Skip to main content

ORM Relations

This page shows practical relation definitions for both SQL and Mongo models, including the driver-aware choices you should make in each workflow.

Relation definitions in model schema

Relations are declared in static schema using the relation helper:
Options are validated at runtime and fed into migration/graph tooling.

Scenario 1: SQL relational model

Use this model style when you need SQL migrations and relational constraints.

Scenario 2: Mongo model runtime

In Mongo flows, join-heavy SQL constraints are replaced by document/reference semantics.

Relation helper compatibility

Tips

  • Keep relation keys/aliases stable (user_id, post_id, morphName, morphAlias) to protect query compatibility.
  • Keep SQL many-to-many explicit with pivot metadata.
  • Keep Mongo models aligned to document boundaries and avoid SQL-only assumptions.
  • Use static database for physical foreign keys and composite indexes. relation(...) is the runtime relation contract, not the full SQL DDL contract.

Learn more