我有一个问题,我有两个模型; “地理封锁”和“国家/地区”,以及关联:
GeoBlockingModel:
Date
协会:
Table2
问题在于,SMALL(above,3)
模型具有两个主键,const TYPE_BLACK = 0x10;
const TYPE_WHITE = 0x20;
export const ETYPE_CONTENT = 0x10;
export default (sequelize, DataTypes) => {
const GeoBlockingModel = sequelize.define('GeoBlocking', {
targetUUID: {
type: DataTypes.UUID,
primaryKey: true,
},
entityType: {
type: DataTypes.INTEGER.UNSIGNED,
primaryKey: true,
validate: {
isIn: {
args: [[
ETYPE_CONTENT,
]],
msg: `Unknow entity type`,
},
},
},
type: {
type: DataTypes.INTEGER.UNSIGNED,
allowNull: false,
defaultValue: TYPE_BLACK,
validate: {
isIn: {
args: [[
TYPE_BLACK,
TYPE_WHITE,
]],
msg: `Unknow type`,
},
},
},
}
//...
和 GeoBlockingModel.associate = function(models) {
CountryModel = models.countries;
GeoBlockingModel.belongsToMany(CountryModel, {
as: 'countries',
through: {
model: 'GeoBlockingCountry',
timestamps: true,
paranoid: false,
},
// foreignKey: ['targetUUID', 'entityType'],
constraints: true,
});
};
。并且仅通过一个字段关联来创建直通模型:
GeoBlocking
如果我取消注释entityType
,该字段将被冠以targetUUID
。
有什么主意吗?