Skip to content

Relationships of a Runtime Type

A view declares its relationships, types included. When the type is data, use gom.edges:

const lyre = nodeRef(ThingNode, 'lyre');
const ada = nodeRef(PersonNode, 'ada', 'Author'); // must also carry the label Author
await gom.edges.relate(lyre, ada, 'OWNED_BY', { since: 1990 });
await gom.edges.relate(lyre, ada, 'PLAYED_BY', {}, RelateMode.CREATE);
const owners = await gom.edges.loadRelated(lyre, 'OWNED_BY', Direction.OUTGOING, PersonNode);
await gom.edges.unrelate(lyre, ada, 'PLAYED_BY'); // every PLAYED_BY from lyre to ada
await gom.edges.unrelateAll(lyre, 'OWNED_BY'); // every OWNED_BY that leaves lyre
  • Both ends are matched, never made. If either is missing, or lacks a label the reference names, nothing is written and relate returns false.
  • RelateMode.MERGE, the default, keeps at most one relationship of the type between the two nodes in that direction, and sets its properties. CREATE makes another each time.
  • unrelate and unrelateAll return how many relationships they removed. No node is deleted.
  • Each marks the relationship token of both ends when it changes something.