嗨,伙计们,我有这两个模型:
const media = sequelize.define('media', {
id: { type: Sequelize.UUID, primaryKey: true, defaultValue: Sequelize.UUIDV4 },
name: { type: Sequelize.STRING, allowNull: false, unique:'compositeIndex' },}, { freezeTableName: true });
const mediaGenre = sequelize.define('mediaGenre', {
id: { type: Sequelize.UUID, primaryKey: true, defaultValue: Sequelize.UUIDV4 }}, { freezeTableName: true, name: { plural: 'mediaGenre' } });
以及这两个关系:
media.hasMany(mediaGenre, as: 'mGenre');
mediaGenre.belongsTo(media);
media.belongsToMany(genre, { through: mediaGenre });
genre.belongsToMany(media, { through: mediaGenre });
当我想创建媒体时,我会:
MediaModels.media.create(
{name: 'Hulk',
mediaGenre: [
{ genreId: '021baab5-7fc6-4b06-aca5-e4b1ed1f3ce4' },
{ genreId: '03f069a4-dc52-4ab5-82d3-6bcd67d2d29e' }]},
{
include: [
{model: MediaModels.mediaGenre, as: 'mGenre'}
]
}
);
这些一直在使用 sequelize 3,最近我更新为 sequelize 4.4.2,它没有抛出错误,但表 mediaGenre 没有被填充。
关于可能是什么错误的任何想法?