sequelize.js - Sequelize CLI access from one model to another - Stack Overflow

I use sequelize-cli migration scripts to create modelsI have created models 'user' and '

I use sequelize-cli migration scripts to create models I have created models 'user' and 'user-role' I want to access to model user_role from the file user This how my directory structure looks like: [folders structure][1] [1]: .png in my user.js file i write

const {user_role} = require('./index')

I suppose to get a user_role class extended from Model class. In user_role class i defined static async function grantRole(user, role) I want to use this function in user.js class. So i write:

await user_role.grantRole(newUser, userRoles.admin)

but in runtime I get an error 'grantRole is not a function'

However I can use this function from other js files that are not in models folders and do not represent a model for db

const {user, user_role} = require('../db/models/index')
const {userRoles} = require('../db/middleware')
try {
    const regUser = await user.register(userCreds.UserName, userCreds.UserMail, userCreds.UserPass) 
    await user_role.grantRole(regUser, userRoles.admin)      
} catch(error) {
    console.log(error.message)
}

What do I do wrong?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744364832a4570650.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信