overlookmotel / sequelize-hierarchy

Nested hierarchies for Sequelize
MIT License
301 stars 92 forks source link

Get error "TypeError: Cannot read property 'try' of undefined" when try to call create method #232

Open Cuberian opened 3 years ago

Cuberian commented 3 years ago

When i try create new record in db, I get that error

(node:3048) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'try' of undefined at Function.afterCreate (C:\Users\theme\PhpstormProjects\Kpop-portal\server\node_modules\sequelize-hierarchy\lib\hooksM odel.js:60:19) at Function.runHooks (C:\Users\theme\PhpstormProjects\Kpop-portal\server\node_modules\sequelize\lib\hooks.js:129:18) at model.save (C:\Users\theme\PhpstormProjects\Kpop-portal\server\node_modules\sequelize\lib\model.js:4033:30) at processTicksAndRejections (internal/process/task_queues.js:97:5) at async Function.create (C:\Users\theme\PhpstormProjects\Kpop-portal\server\node_modules\sequelize\lib\model.js:2207:1 2) at async create (C:\Users\theme\PhpstormProjects\Kpop-portal\server\controllers\commentController.js:7:9) (node:3048) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/ cli.html#cli_unhandled_rejections_mode). (rejection id: 18)

My code:

async create(req, res) {
        const {text, parentId, user_id, publication_id} = req.body;
        await Comment.create({text, parentId, likes:0, dislikes:0, user_id, publication_id});
        return res.json({message: 'ok'})
    }
phamquoctuan1 commented 2 years ago

you miss =>