0
我試圖創建一個多到許多使用關係sequelize,但每次我嘗試使用此功能:Sequelize多到許多錯誤:user.addProjects不是一個函數
user.addProject(project, { through: { status: 'started' }})
我的服務器死機了,我得到這個錯誤:
user.addProjects is not a function at User.create.then.user
var connection = new Sequelize('database', 'root', 'phase_99');
var User = connection.define('user', {title: Sequelize.STRING});
var Project = connection.define('project', {title: Sequelize.STRING});
var UserProjects = connection.define('userProjects', {
status: Sequelize.STRING
})
User.belongsToMany(Project, {as: 'Workers', through: UserProjects, foreignKey: 1 })
Project.belongsToMany(User, { as: 'Tasks', through: UserProjects, foreignKey: 1 })
connection.sync().then(() => {
var project = Project.create({title: 'ISD Corp'})
User.create()
.then(user => {
user.addProject(project, { through: { status: 'started' }})
})
});
我不知道我做錯了,我也跟着文檔,而這個功能是假設自動生成