我最终希望相册在图库应用程序中包含子相册。我定义了以下ES6模型:
class Album extends Sequelize.Model {
static init (sequelize, DataTypes) {
return super.init({
name: DataTypes.STRING,
description: DataTypes.STRING
}, { sequelize })
}
static associate (models) {
this.belongsToMany(models.Media, {
through: 'media_to_albums'
})
this.hasMany(models.Album, { as: 'children', foreignKey: 'parentId' });
this.belongsTo(models.Album, { as: 'parent', foreignKey: 'parentId' });
}
}
module.exports = Album
稍后在代码中,当我尝试调用“ myAlbum.setParent(anotherAlbum.id)”时,出现错误“ setParent不是函数”。我想念什么?