RelationBuilder
Configures a Relation declared from one Template or Union to another.
Remarks
Section titled “Remarks”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.
- TemplateBuilder.addRelation
- Relate items
- RelationDefinition for the emitted Definition
- ReadRelationInstance for navigating the Relation from an Item
Extends
Section titled “Extends”Properties
Section titled “Properties”cardinality
Section titled “cardinality”
readonlycardinality:RelationCardinality
Cardinality read from the from side to the to side, such as many-to-one.
evented
Section titled “evented”
readonlyevented: (key?) =>EventBuilder
Publishes an Event on the from Item whenever the Relation is set, added to, removed from or
cleared, and returns that Event.
Parameters
Section titled “Parameters”string
Event key; defaults to the Relation’s fromKey.
Returns
Section titled “Returns”The Event builder, for registering Listeners.
Remarks
Section titled “Remarks”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.
Example
Section titled “Example”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);});fromKey
Section titled “fromKey”
readonlyfromKey:string
Relation key on the from Template or Union.
readonlyprn:string
Platform Resource Name of the declared resource, derived from the App key and resource key.
Inherited from
Section titled “Inherited from”
readonlytoKey: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.
Methods
Section titled “Methods”setDescription()
Section titled “setDescription()”setDescription(
description):this
Sets the description emitted into the definition and rendered in generated reference and application assets.
Parameters
Section titled “Parameters”description
Section titled “description”string
Human-readable description of the resource.
Returns
Section titled “Returns”this
This builder for chaining.

