A link stores a cross-module relationship in an app-owned junction table. The two modules remain independent and never import each other.
users <-> user_organization <-> organizations
Define both endpoints
// src/links/user/models/user-organization.ts
import { defineLink } from "@damatjs/framework";
export default defineLink(
{ module: "user", model: "users", field: "users" },
{
module: "organization",
model: "organizations",
field: "organizations",
},
);
moduleis the ID used bygetModule.modelis the key in that module's collected model map and service.fieldis the relationship name exposed on the linked side.
The generated junction has a unique pair index, an index for each side, soft delete, and timestamps. Cross-module database foreign keys are off by default to preserve module isolation.
Aggregate link owners
src/links/
├── index.ts
└── user/
├── index.ts
├── models/user-organization.ts
└── migrations/
The owner index exports links and collectLinkModels(links). The top-level
index combines every owner and default-exports defineLinkModule(links). Point
damat.config.ts at it with links: "./src/links".