GenericLink
A class whose instances represent runtime values of fields in heap tables declared through Heap.GenericLink.
It provides a convenient interface for working with the link.
Using this class separately, outside the value of a table field, is not useful and is not supported.
Properties and Methods
-
type:
string
The identifier of the table that this link points to. It matches the type property of the corresponding table. -
id:
string
A unique identifier for the specific record that this field value points to. -
get(ctx: app.Ctx):
Promise<HeapObject>
"Syntactic sugar" for executing the getById request to the target table with the target identifier. It returns the heap object that the current link value points to.Unlike RefLink.get, the returned object has a TypeScript type of a generic heap object without being tied to a specific table type, as it is not known in advance which table the link points to. To clarify the object's type, it is recommended to use the isMyRecord method.
- ctx:
app.Ctx
The request context. Used for internal implementation and also allows the request to be executed in the desired transaction.
- ctx:
-
getTargetTableRepo(ctx: app.Ctx):
Promise<HeapTableRepo>
Returns the repository of the table that the current field value points to. Note that this method is asynchronous.- ctx:
app.Ctx
The request context. Used for internal implementation.
- ctx:
Examples
Determining the name of the object on which the task was created.
const Tasks = Heap.Table('tasks', {
title: Heap.String(),
basedOn: Heap.GenericLink(),
})
const task = await Tasks.getById(ctx, req.params.id)
const basedOn = await task.basedOn.get(ctx)
const baseOnDisplayName = Orders.isMyRecord(basedOn)
? 'Order #' + basedOn.num
: Tasks.isMyRecord(basedOn)
? 'Task ' + basedOn.title
: 'Unexpected based-on object ' + task.basedOn.type + ' ' + task.basedOn.id