node.js sequelize关联,包括条件 [英] node.js sequelize associations, include on condition

查看:104
本文介绍了node.js sequelize关联,包括条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在findAll查询的include数组中传递条件?

Is it possible to pass a condition in the include array of a findAll query?

例如,我有UsersModel,PostsModel和UserVotesModel.

For example I have UsersModel, PostsModel and UserVotesModel.

用户可以对帖子进行投票.

Users can vote on posts.

对于已登录的用户,我要查询帖子,并且仅包含当前用户的投票.我无法使用Sequelize的include参数来做到这一点. Sequelize在postId上加入帖子和UserVotes,但是对于这个特定的查询,我想在postId和UserId上都加入.

For the logged in user I want to query posts and include only the vote for the current user. I am not able to do this using Sequelize's include param. Sequelize joins posts and UserVotes on postId, but for this specific query I want to join on both postId and UserId.

有什么想法可以解决这个问题吗?

Any ideas how to solve this problem?

推荐答案

我刚刚检查了Sequelize源代码.这是不可能的!

I just checked Sequelize source code. This is not possible!

这篇关于node.js sequelize关联,包括条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆