我正在尝试创建仅由两个外键SEATS_ID和SCREENING_ID组成的表OCCUPIED_SEATS,这两个外键均构成唯一索引。
如何在Sequelize中做到这一点?
我尝试在OCCUPIED_SEATS和其他文件的FK中创建索引。
const SEATS = require("./Seats");
const SCREENING = require("./Screening");
const OCCUPIED_SEATS = sequelize.define("OCCUPIED_SEATS", {
//SEATS_ID
//SCREENING_ID
},
{
indexes: [
{
unique: true,
fields: [SEAT_ID, SCREENING_ID]
}
],
underscored: true
}
);
OCCUPIED_SEATS.belongsTo(SEATS, {foreignKey: 'SEAT_ID'});
OCCUPIED_SEATS.sync();
module.exports = OCCUPIED_SEATS;
const OCCUPIED_SEATS = require("./Occupied_Seats");
const SEATS = sequelize.define("SEATS", {
//ROOM_ID
SEATS_ID: {
type: Sequelize.INTEGER,
primaryKey: true,
allowNull: false,
autoIncrement: true
},
ROW: {
type: Sequelize.STRING,
allowNull: false,
},
COLUMN: {
type: Sequelize.INTEGER,
allowNull: false
},
},
{
underscored: true
}
);
SEATS.hasMany(OCCUPIED_SEATS, {foreignKey: 'SEAT_ID'});
module.exports = SEATS;
我得到以下错误。
错误:SEATS.hasMany调用的不是Sequelize.Model的子类。