Skip to content

Moving a record

Anton Demushkin edited this page Aug 4, 2019 · 2 revisions

To move a record you need to get its instance before.

const tagToMove = await Tag.find(1234);
const destinationTag = await Tag.find(321);

await tagToMove.moveAsPrevSiblingOf(destinationTag);
// or
await tagToMove.moveAsLastChildOf(destinationTag);
// or
await tagToMove.makeRoot();
// or another function from the list

Warning! You can move record only if it's a valid node == it has its own place in the tree == it has left and right values. If it doesn't, please see Creating a record page.

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

Move as previous sibling

Move the node (from which you call the function) as previous sibling of destination node.

async record.moveAsPrevSiblingOf(destNode, options = {})

Move as next sibling

Move the node (from which you call the function) as next sibling of destination node.

async record.moveAsNextSiblingOf(destNode, options = {})

Move as first child

Move the node (from which you call the function) as first child of destination node.

async record.moveAsFirstChildOf(destNode, options = {})

Move as last child

Move the node (from which you call the function) as last child of destination node.

async record.moveAsLastChildOf(destNode, options = {})

Make node root

Make this node a root node and move all its descendants to the new tree. Only for multiple-root trees.

async record.makeRoot(options = {})

Clone this wiki locally