RefLink
A class whose instances represent runtime values of fields in heap tables declared through Heap.RefLink.
It provides a convenient interface for working with references.
Using this class separately, outside the value of a table field, is not useful and is not supported.
Properties and Methods
-
<b id="type">type</b>:
string
The identifier of the table that this reference points to. It matches the property type of the corresponding table. -
<b id="id">id</b>:
string
A unique identifier of the specific record that this field value points to. -
<b id="get">get(ctx: app.Ctx)</b>:
Promise<
HeapObject>
A "syntactic sugar" for executing a getById request to the target table with the target identifier. Returns the heap object that the current reference value points to. The returned object has the correct TypeScript type corresponding to the "shape" of the target table.- <b id="get_ctx">ctx</b>: app.Ctx
The request context. Used for internal implementation and also allows the request to be executed in the desired transaction.
- <b id="get_ctx">ctx</b>: app.Ctx
-
<b id="getTargetTableRepo">getTargetTableRepo(ctx: app.Ctx)</b>: HeapTableRepo
Returns the repository of the target table that this field points to.- <b id="getTargetTableRepo_ctx">ctx</b>: app.Ctx
The request context. Used for internal implementation.
- <b id="getTargetTableRepo_ctx">ctx</b>: app.Ctx
Examples
Conveniently getting the project name by task
const Tasks = Heap.Table('tasks', {
title: Heap.String(),
project: Heap.RefLink('projects'),
})
const task = await Tasks.getById(ctx, req.params.id)
const project = await task.project.get(ctx)
ctx.console.log('project name', project.name)