I currently has
const User = db.define(
'users',
{
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
email: {
type: Sequelize.STRING(255)
},
}
const UserRole = db.define(
'user_roles',
{
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
}
},
);
const Role = db.define(
'organization_roles',
{
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
roleName: Sequelize.STRING(255),
},
);
User.belongsToMany(Role, {
as: 'roles',
through: UserRole,
foreignKey: 'userId'
});
Role.belongsToMany(User, {
as: 'organizationUsers',
through: UserRole,
foreignKey: 'roleId'
});
How can I query all the User which doesn't have specific role?
For example:
User1 has role: Teacher, Guardian
User2 has role: Teacher
I want to query user that not have Guardian in their role --> I will get User2.