我是这个续集的新手。我尝试使用belongsToMany通过UserPermissions在用户和权限之间关联模型,这是我的代码。
-- 用户.js
const bcrypt = require('bcrypt');
const config = require('../config/general');
module.exports = (sequelize, DataTypes) => {
const User = sequelize.define('User', {
email: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
validate: {
isLowercase: true,
notEmpty: true,
isEmail: true
}
},
username: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
validate: {
isLowercase: true,
notEmpty: true,
min: 3
}
},
salt: {
type: DataTypes.STRING,
allowNull: true
},
password: {
type: DataTypes.STRING,
allowNull: false,
validate: {
notEmpty: true
}
},
}, {
underscored: …Run Code Online (Sandbox Code Playgroud)