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?