Link types
A link type is a named relationship between two object types. Links are what turn a set of tables into a model you can walk: from a failed quality check to the batch it was taken from, to the deliveries that carried that batch, to every shop holding the lot. This page covers how link types are defined, the three ways to back them, how they are stored and traversed, and how actions change them
In the platform today
- A link type is a foreign key, defined in
ontology.yamlas{ from, to, via, name, reverse }:fromis the type that holds the key propertyvia,tois the type it points at, andnameandreversename the two sides on screen, as in thelot-batchexample below - Many to many relationships use an intermediate object type with two foreign key links, which is the join object backing below
- A query follows a link by its link type ID in either direction, up to 3 hops, with the reader's access applied at every hop, and
GET /api/v2/types/{type}/objects/{key}/links/{link}returns one object's linked objects
- Join tables, the
sidesandcardinalitydefinition, side IDs, link and unlink rules and the index storage on this page
Anatomy of a link type
Every link type is read from both ends, its two sides. The relationship is stored once, and each side gets its own name, so a delivery “delivers to” shops while a shop “receives” deliveries. Each side has its own ID, display name and display priority, and each side's cardinality says how many objects the other end can reach. A link type can connect a type to itself, and two types can have several link types between them
In ontology.yaml a link type is a foreign key with a name for each side
linkTypes:
delivery-stop-shop:
{ from: delivery-stop, to: shop, via: shopId, name: Delivers to shop, reverse: Deliveries }
On request, each side also gets its own ID, display name and display priority, set in a fuller definition with sides and cardinality
Cardinality
Cardinality is a statement about the real world, enforced by the backing. Pick the one that is true of the operation, not the one that is convenient for today's data
| Cardinality | Meaning | Allowed backings | Example |
|---|---|---|---|
| One to one | Each object on either side links to at most one on the other | Foreign key | Ingredient ↔ Commodity price, when each ingredient has one market price |
| Many to one | Many objects on one side link to one on the other | Foreign key | Many Shipped lot → one Production batch |
| Many to many | Objects on both sides link to many on the other | Join table or join object | Reefer delivery ↔ Scoop shop |
A one to one link is checked when the backing data is indexed: if two objects claim the same partner, the second link is rejected and reported, and the objects themselves still index. Many to one and one to many are the same link type seen from different sides; the definition always records the "one" side as the target of the foreign key
How links are backed
The backing decides where link data lives, how it is edited and what it costs. Choose it from the cardinality and from one question: does the relationship carry data of its own
Foreign key
A property on one type holds the primary key of an object of the other type. This is the cheapest backing, needs no extra dataset and is the only option for one to one and many to one links. The foreign key property must have the same base type as the target's primary key. A foreign key value with no matching target is kept on the object and reported as a dangling link in the type's health view, which usually points at a pipeline that publishes children before parents
lot-batch:
{ from: lot, to: batch, via: batchNo, name: Lot of batch, reverse: Lots }
Join table
On request, a dataset with one column holding the primary key of each side and one row per link. Use it for many to many relationships that carry no data of their own. If people need to add and remove these links through actions, the link type must be join-table backed or object-backed, because there is no single property to modify
Join object
An object type that sits between the two sides, with a many to one link to each. Use it whenever the relationship has data: a Silo draw records how many litres of which silo went into which batch, and a Manifest line records how many of which product ride on which run. The join object has its own key, properties, actions, status and security, and the two outer types are still traversable in one step through a shortcut side that the link type declares
In ontology.yaml a join object is an object type with two foreign key links. On request, a shortcut side traverses it in one step
silo-draw-silo:
{ from: silo-draw, to: silo, via: siloId, name: Draws from, reverse: Draws }
silo-draw-batch:
{ from: silo-draw, to: batch, via: batchNo, name: Feeds, reverse: Milk from }
Relationships tend to grow data. A join table that later needs a quantity or a date has to be migrated to a join object, which changes how its links are edited. Starting with a join object costs one more object type and saves the migration
How links are stored and indexed
On request, links are kept in the index, so a hop is a lookup rather than a join. Many to many links cost the most storage, which rarely matters for the illustrative ice cream maker's delivery stops but does for links like "sensor reading belongs to asset", which should usually be a time series instead of objects and links
Traversing links
Following a link turns an object set of one type into an object set of the other. In the SDK this is follow with the link type's ID, and on request with the side's ID; in apps it is the link list on an object, or following links in exploration views. A single query can follow up to 3 hops. Each hop applies the reader's row access and access labels before the next one starts
// Recall scope: every lot not yet sold through
// from a batch that failed a quality check
const lots = await mso.objects("qatest")
.where({ kind: "Net quantity check", result: "Fail", sampled: { $gte: "2026-10-20" } })
.follow("tested-batch-test") // hop 1: into the Tested batch join object
.follow("tested-batch-batch") // hop 2: on to the batch, many to one
.follow("lot-batch") // hop 3: the batch's lots
.where({ status: { $ne: "Sold through" } })
.page({ pageSize: 100 });
For one object, the REST API returns its linked objects directly, paged like any object list. The link is named by its link type ID, here the foreign key link from Shipped lot to Production batch, read from the batch's end
On request: a single linked object by its key, as GET /api/v2/types/batch/objects/B-0841/links/lot-batch/LOT-0841-2
| Limit | Default | Notes |
|---|---|---|
| Hops per query | 3 | Deeper paths usually mean a missing link type |
| Links returned per page | 100 by default, 1,000 at most | Paged like any object list |
Other limits on links are set per implementation
Editing links
Links change in two ways: when the backing data changes, through sync, and when an action changes them. How an action changes a link depends on the backing
- Foreign key. A modify rule sets the foreign key property. Moving lot
LOT-0841-2to the batch it really came from is an edit ofbatchNo - Join table. On request, link and unlink rules name the link type and the two objects
- Join object. Create and delete rules on the join object type. Planning a draw of 1,300 L from
SIL-2intoB-0844creates aSilo drawobject
Writeback for link edits uses the same connectors as property edits; the dispatch system sees a removed stop as a dropped stop on the run
Security on links
A link is visible only when the reader can see both of its ends. If a shift lead can see Staffing schedule objects only for their own shop, the shift-shop link from any Scoop shop lists only their own shop's schedules for that shift lead, and counts and derived properties over the link are computed the same way. There is no separate permission on a foreign key or join table link
Access labels on a join table apply to the links it backs. A join object has its own row access, field access and access labels, which makes it the right backing when the relationship itself is sensitive: a Pickup stop join object, a farm's milk ticket on a tanker run, carries SUPPLIER-CONF while the Milk pickup it belongs to stays INTERNAL
Naming and design guidance
- Name each side for what you reach, read from its own end:
destinationShopsfrom a run,inboundDeliveriesfrom a shop. Avoid names likelink1orshopDeliverythat read the same from both ends - Use the plural for sides that reach many and the singular for sides that reach one, so
lot.batchandbatch.lotsread as English in code - When a type has several relationships, name each for its role: a
Shipped lothasLot at shop,Lot on runandLot stored in, not three links calledplace - Self links need a direction:
Production batch→reworkedFromandreworkedInto - Do not store a count of links as a property. Use a derived property such as
openDeliveryCount, which is always right - Do not copy a value across a link, such as the shop's province onto each delivery. Traverse the link or derive it
Limitations
- A query follows at most 3 link hops. Longer paths need a direct link type maintained by a pipeline
- One to one and many to one links can only be backed by a foreign key, and many to many links only by a join table or a join object
- Foreign key links cannot be added or removed with link and unlink rules. They change only by editing the foreign key property
- A join table carries no data of its own and backs exactly one link type. Moving it to a join object later is a migration that changes how its links are edited
- Links have no permission of their own. A link is visible only when the reader can see both ends, and a sensitive relationship needs a join object to carry its own access labels
- Dangling foreign keys are kept and reported, not rejected. A traversal from them returns nothing until the target object exists