我在用户和电影之间有一个n:m关联
const UserMovie = db.define('user_movie', {
state: {
type: Sequelize.BOOLEAN,
allowNull: false,
},
});
User.belongsToMany(Movie, { through: UserMovie });
Movie.belongsToMany(User, { through: UserMovie });
我想查询UserMovie按电影获取用户组的计数,其中state为“true”。所以我写道:
user_movie: {
type: new GraphQLList(UserMovie),
args: {
offset: {
type: GraphQLInt
},
limit: {
type: GraphQLInt
},
users: {
type: new GraphQLList(GraphQLInt)
}
},
resolve (root, args) {
return db.models.user_movie.findAll({
offset: args.offset,
limit: args.limit,
where: {
state: true,
userId: [args.users]
},
attributes: ['movieId', [sequelize.fn('COUNT', sequelize.col('userId')), 'usercount']],
group: 'movieId',
});
}
},
但每次我查询它时,都会返回一个usercount null
感谢您的帮助。