Skip to content

Getting records

Anton Demushkin edited this page Jul 5, 2021 · 2 revisions

It's possible to fetch records using the Model:

const rootTag = await Tag.fetchRoot();
// or
const rootTags = await Tag.fetchRoots();
// or
const tags = await Tag.fetchTree();

or using a record:

const someTag = await Tag.find(1234);

const siblingTag = await someTag.getPrevSibling();
// or
const childrenTags = await someTag.getChildren();
// or
const numberOfLeafs = someTag.getNumberDescendants();
// or another function from the list

Let's call the Model as Model and the instance of that model as record.

Fetch root node

Get root node for selected rootId.

async Model.fetchRoot(rootId = 1, options = {}): record|false

Fetch tree

Get all tree nodes.

async Model.fetchTree(depth = 0, rootId = 1, options = {}): [record]|false

Fetch roots

Get all root nodes.

async Model.fetchRoots(options = {}): [record]|false

Get previous sibling

Get previous sibling of the node.

async record.getPrevSibling(options = {}): record|false

Get next sibling

Get next sibling of the node.

async record.getNextSibling(options = {}): record|false

Get siblings

Get all siblings of the node including current node or not.

async record.getSiblings(withCurrentNode = false, options = {}): [record]

Get first child

Get first child of the node.

async record.getFirstChild(options = {}): record|false

Get last child

Get last child of the node.

async record.getLastChild(options = {}): record|false

Get children

Get all children of the node.

async record.getChildren(options = {}): [record]|false

Get descendants

Get all or limited by depth descendants for the node.

async record.getDescendants(depth = 0, options = {}): [record]|false

Get parent

Warning! If you have parentId, then it uses only options.transaction and options.searchPath.

async record.getParent(options = {}): record|false

Get ancestors

Get all or limited by depth ancestors for the node.

async record.getAncestors(depth = 0, options = {}): [record]|false

Get number of children

Get number of direct children nodes (only from one next level).

async record.getNumberChildren(options = {}): number

Get number of descendants

Get number of descendants (children and their children).

record.getNumberDescendants(): number

Clone this wiki locally