【发布时间】:2019-04-15 07:25:12
【问题描述】:
我正在使用 sequelize.js V.5 创建一个简单的 api,用于发布书籍的 cmets。评论应该通过图书 id 属于图书,并且对于发布的用户来说也是一样的。
我不太确定如何创建它。
//user model
...
User.hasMany(models.Comment)
...
//book model
...
Book.hasMany(models.Comment);
...
//comment model
...
Comment.belongsTo(models.User);
Comment.belongsTo(models.Book);
...
//route
...
Comment.create(
{
//what do i put here? or what other syntax i use
}
)
【问题讨论】:
标签: node.js sequelize.js associations