Skip to content

RelationBuilder

Configures a Relation declared from one Template or Union to another.

A Relation reads from its declaring side to its target: an employee has one parking space is declared from employee to parkingSpace with cardinality one-to-one. Items navigate the Relation from either side, so which side is from is a domain modeling decision. Cardinality is read from the from side; a many-to-one Relation gives each from Item one target and each target many from Items.

readonly cardinality: RelationCardinality

Cardinality read from the from side to the to side, such as many-to-one.


readonly evented: (key?) => EventBuilder

Publishes an Event on the from Item whenever the Relation is set, added to, removed from or cleared, and returns that Event.

string

Event key; defaults to the Relation’s fromKey.

EventBuilder

The Event builder, for registering Listeners.

The Event is declared on the from Template or Union with a payload of action (added, cleared, removed or set), otherId (the other Item) and relationPrn. Calling it again returns the same Event.

Reacting to a change of manager

const managerChanged = employee.addRelation('manager', 'many-to-one', employee, { toKey: 'manages' }).evented();
managerChanged.addListener('notify', async (event, item, current, ctx) => {
await ctx.log('manager changed', item.id);
});

readonly fromKey: string

Relation key on the from Template or Union.


readonly prn: string

Platform Resource Name of the declared resource, derived from the App key and resource key.

BaseBuilder.prn


readonly toKey: string

Relation key on the to Template or Union, used when navigating from the target back. It defaults to fromKey; pass toKey in the options to use a different term, such as manages for the reverse of manager.

setDescription(description): this

Sets the description emitted into the definition and rendered in generated reference and application assets.

string

Human-readable description of the resource.

this

This builder for chaining.

BaseBuilder.setDescription