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

3 cardinalitiesOne to one, many to one, many to many
3 backingsForeign key, join table, join object
3 hopsPer query
Both sidesNamed, typed and permissioned separately

In the platform today

Built
  • A link type is a foreign key, defined in ontology.yaml as { from, to, via, name, reverse }: from is the type that holds the key property via, to is the type it points at, and name and reverse name the two sides on screen, as in the lot-batch example 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
On request
  • Join tables, the sides and cardinality definition, 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

Reefer deliveryDLV-5521 Scoop shopSHP-HFX side A: destinationShops, reaches many shops delivery-shop side B: inboundDeliveries, reaches many deliveries
Each side is named for what you reach by following it. From a run you see its destination shops; from a shop you see its inbound deliveries

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

CardinalityMeaningAllowed backingsExample
One to oneEach object on either side links to at most one on the otherForeign keyIngredient ↔ Commodity price, when each ingredient has one market price
Many to oneMany objects on one side link to one on the otherForeign keyMany Shipped lot → one Production batch
Many to manyObjects on both sides link to many on the otherJoin table or join objectReefer 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 Shipped lotbatchNo = B-0841 Production batchbatchNo B-0841 (key) many to one Join table Reefer deliveryDLV-5521 delivery_stopsdeliveryId · shopId Scoop shopSHP-HFX Join object Raw milk siloSIL-1 Silo drawDR-6104 · 1,270 L Production batchB-0841 many to one many to one
A join object is an object type in its own right, with two many-to-one links. Use it when the relationship has properties, a lifecycle or its own security

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 }
Start with a join object when in doubt

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

GET /api/v2/types/batch/objects/B-0841/links/lot-batch?pageSize=100

On request: a single linked object by its key, as GET /api/v2/types/batch/objects/B-0841/links/lot-batch/LOT-0841-2

LimitDefaultNotes
Hops per query3Deeper paths usually mean a missing link type
Links returned per page100 by default, 1,000 at mostPaged 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-2 to the batch it really came from is an edit of batchNo
  • 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-2 into B-0844 creates a Silo draw object

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: destinationShops from a run, inboundDeliveries from a shop. Avoid names like link1 or shopDelivery that read the same from both ends
  • Use the plural for sides that reach many and the singular for sides that reach one, so lot.batch and batch.lots read as English in code
  • When a type has several relationships, name each for its role: a Shipped lot has Lot at shop, Lot on run and Lot stored in, not three links called place
  • Self links need a direction: Production batch → reworkedFrom and reworkedInto
  • 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

Related