【发布时间】:2016-11-23 00:29:03
【问题描述】:
我有以下结构:
var User = sequelize.define('user', {
name: DataTypes.STRING
});
var Post = sequelize.define('post', {
text: DataTypes.STRING
});
var PostComment = sequelize.define('postComment ', {
id: {
type: DataTypes.BIGINT,
primaryKey: true,
autoIncrement: true
},
comment: DataTypes.TEXT
});
Post.belongsToMany(User, {as: 'postUserComment', through: {model: models.PostComment, unique: false}, foreignKey: 'idPost'});
User.belongsToMany(Post, {through: {model: models.PostComment, unique: false}, foreignKey: 'idUserComment'});
我可以为同一个用户创建多个 cmets。
但如果我对同一个用户的同一篇文章有多个评论,并尝试通过以下方式选择它们:
Post.findAll({
include: [{model: models.User, as: 'postUserComment', attributes:['name'], through: {attributes: ['comment']}},
limit: 10,
offset: 0,
order: "id DESC"
...
它只为帖子中的每个用户返回 1 条评论。我该怎么做才能全部选中?
方言:mysql, 续集版本:~3.27.0
【问题讨论】:
标签: mysql node.js sequelize.js