sequelize / sequelize/sequelize
users.belongsToMany called with something that's not a subclass of Sequelize.Model
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 30.4k
- Forks
- 4.3k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 68
Description
const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');
const Role = require('../models/Role');
const UserRole = require('../models/UserRole');
const Permission = require('../models/Permission');
const UserPermission = require('../models/UserPermission');
const User = sequelize.define('users', {
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true
},
name: {
type: DataTypes.STRING,
allowNull: false,
},
lastName: {
type: DataTypes.STRING,
defaultValue: ''
},
email: {
type: DataTypes.STRING,
unique: true,
allowNull: false,
},
emailToken: {
type: DataTypes.TEXT
},
emailTokenExpired: {
type: DataTypes.DATE
},
isEmailVerified: {
type: DataTypes.TINYINT,
defaultValue: 0,
comment: '1 = Verified, 0 = Not Verified',
allowNull: false,
},
mobile: {
type: DataTypes.STRING,
unique: true,
},
mobileToken: {
type: DataTypes.TEXT
},
mobileTokenExpired: {
type: DataTypes.DATE
},
isMobileVerified: {
type: DataTypes.TINYINT,
defaultValue: 0,
comment: '1 = Verified, 0 = Not Verified',
allowNull: false,
},
password: {
type: DataTypes.STRING,
},
passwordToken: {
type: DataTypes.TEXT
},
passwordTokenExpired: {
type: DataTypes.DATE
},
otp: {
type: DataTypes.STRING
},
otpExpired: {
type: DataTypes.DATE
},
authToken: {
type: DataTypes.TEXT
},
googleId: {
type: DataTypes.STRING
},
facebookId: {
type: DataTypes.STRING
},
appleId: {
type: DataTypes.STRING
},
bankId: {
type: DataTypes.STRING
},
status: {
type: DataTypes.ENUM('active', 'inactive', 'delete'),
defaultValue: 'active',
allowNull: false,
},
});
User.belongsToMany(Role, {
through: UserRole,
targetKey: 'id',
foreignKey: 'userId'
});
User.belongsToMany(Permission, {
through: UserPermission,
targetKey: 'id',
foreignKey: 'userId'
});
sequelize.sync({
// alter: true
}).then(() => {
console.log('users table synchronized successfully!');
}).catch((error) => {
console.error('Unable to synchronized table: ', error);
});
module.exports = {
User
};
/media/dapl-asset-253/dbe82a71-4457-4c23-a401-c78b3cb4b732/var/www/html/Node Office Projects Aritra/crowdfunding-backend/node_modules/sequelize/lib/associations/mixin.js:33
throw new Error(${this.name}.belongsToMany called with something that's not a subclass of Sequelize.Model);
^
Error: users.belongsToMany called with something that's not a subclass of Sequelize.Model
How To Solve This Error ?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the model entry point shown in the issue and inspect config/database plus models/Role, UserRole, Permission, and UserPermission to verify how each imported value is initialized. Reproduce the belongsToMany setup and trace which argument is not recognized as a Sequelize Model. Done means the associations initialize without this error and the model setup is documented or covered by a reproduction test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100