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

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

问题描述

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

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 的包含参数来做到这一点.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 续集关联,包括条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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