Relationships
How tables point at each other — ref, scope and fanout on a field, and the relationship kinds a recipe can declare.
Last updated 2026-09-13 · Generated from recipe-rules.ts + recipe-vocab.json · Markdown
A relationship is a field that points at a real row in another table. ref names the target as Table.column; scope keeps parent and child agreeing on a shared column; fanout decides whether children spread evenly across parents or a few parents own most. The engine builds parents first, so every reference resolves. The relationship kinds a recipe can declare are after, aggregate, fk, polymorphic, unique.
On a field
- ref (e.g. Customer.id) — Points at a real row in another table. Written as Table.column. The engine builds parents before children, so the value is always real.
- scope (e.g. state) — Only points at a row that agrees with this one. Names a column both rows share — the parent picked will match this row on it.
On a table
- tree — A hierarchy built level by level — loops impossible.
- graph — Parts connected through an edge table, quantities multiplied.
Relationship kinds
- after, aggregate, fk, polymorphic, unique. fk is honoured by the reference resolver rather than a kind branch. Values in the GraphRelationship doc comment but NOT listed here (sum, difference, product, ratio, consistency, derived) have no branch in generate.rs — use derive on the field instead.
fanout values
- even, exact, flat, long_tail, one_to_one, power_law, steep, uniform
A scoped reference with a hot-spot
{
"name": "customer_id",
"ref": "Customer.id",
"scope": "state",
"fanout": "power_law"
}The parent picked shares this row’s state, and a few customers get most of the rows.
Common questions
Can a child point at a parent in a different state?
Not when scope names the column. scope: "state" makes the engine pick a parent whose state matches the child’s, so an address and its customer agree. Without scope any parent row is fair game.
How do I make a few parents own most children?
Set fanout on the ref field: power_law or steep for a hot-spot, even or flat for a fair spread, one_to_one or exact when each parent gets a fixed number. The choices are even, exact, flat, long_tail, one_to_one, power_law, steep, uniform.