-
models/index.js const { sequelize, DataTypes } = require('../config/db');
const Comment = require('./Comment')(sequelize, DataTypes);
module.exports = { Comment } models/Comment.js const ns = require('sequelize-nested-set');
module.exports = async (sequelize, DataTypes) => {
const Comment= ns(
sequelize,
DataTypes,
'postComment',
{},
{
tableName: 'post_comments',
levelColumnName: 'level',
rootColumnName: 'rootId',
hasManyRoots: true,
}
);
return Comment;
}; app.js const { Comment } = require('./models');
(async () => {
/*
const record = Comment.build();
const comment = await Comment.createRoot(record);
OR
const comment = await Comment.createRoot();
OR
const comment = await Comment.findByPk(1);
*/
})(); I always get errors that such methods do not exist. const record = Comment.build();
const comment = await Comment.createRoot(record); Then everything works. All my other models without ns functions work as intended. |
Beta Was this translation helpful? Give feedback.
Answered by
fremail
Oct 22, 2021
Replies: 1 comment 1 reply
-
@woodjs I think In other words, models/Comment.js exports a function which returns a promise instead of |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
woodjs
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@woodjs I think
async
in models/Comment.js is excess. Either you need to remove theasync
or use it withawait
in models/index.js.In other words, models/Comment.js exports a function which returns a promise instead of
Comment