尝试进行自我关联时将“不是函数”定为

时间:2019-05-17 02:32:05

标签: node.js sequelize.js

我最终希望相册在图库应用程序中包含子相册。我定义了以下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不是函数”。我想念什么?

0 个答案:

没有答案