Closed xuanngo2001 closed 2 years ago
How to add child node to root node? I got error message "TypeError: root.addChild is not a function". Here is my code.
const { Sequelize, DataTypes, BulkRecordError } = require('sequelize'); const ns = require('sequelize-nested-set'); // Connect to database. const sequelize = new Sequelize({ dialect: 'sqlite', storage: 'treeorg.sqlite' }); // Define Tree model. const Tree = ns(sequelize , DataTypes , 'Tree' , { label: DataTypes.STRING } , { //tableName: 'Tree' timestamps: false , hasManyRoots: true , levelColumnName: 'level' } ); // Create root record. sequelize.sync() .then(() => { let root = new Tree(); root.label = 'Root record'; root = Tree.createRoot(root); let childNode = new Tree(); childNode.label = 'child node'; root.addChild(childNode); });
Closed. Need to wrap code around (async () => { .... })();
(async () => { .... })();
How to add child node to root node? I got error message "TypeError: root.addChild is not a function". Here is my code.