AI agents: fetch the documentation index at llms.txt. Markdown versions are available by appending .md to any page URL, including this page's markdown.
Model relationships
Define references, collections, and back-references between models with lazy and eager loading.
Define foreign keys, inverse collections, and ordered lists with six relationship decorators.
Relationship decorators at a glance
| Decorator | Direction | Cardinality | Creates foreign key? |
|---|---|---|---|
@Reference | Model A -> Model B | One-to-one | Yes (on A) |
@ManyToOne | Model A -> Model B | Many-to-one | Yes (on A) |
@OneToMany | Model B -> Model A[] | One-to-many | No (uses A's foreign key) |
@BackReference | Computed inverse | Varies | No |
@ReferenceArray | Model A -> Model B[] | Ordered list | Yes (array field on A) |
@ReferenceCollection | Alias for @OneToMany | One-to-many | No |
@Reference: belongs to
One-to-one relationship where the current model holds the foreign key.
import { Model, ClientModel, Property, Reference } from "@stratasync/core"