如何使用 sequelize 运行递归查询? [英] How to run recursive queries with sequelize?
本文介绍了如何使用 sequelize 运行递归查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
事情就是这样.我有这个查询:
Here is the thing. I have this query:
const usersManagedByMe = await users.findAll(
{ include: [
{ model: classic_users, where: { manager_id: classicUserIds}, include:[
{ model: workgroups, where: { id: workGroupIds} }
] }
], where: { enabled: true} } );
现在的情况是,如果我找到我管理的某个人,我还需要检查该用户是否管理其他人,并且至少在 10 个级别内也是如此.
What is happening is that if I find a someone I managed I will need to also check if this user manage someone else and the same at least for 10 levels.
你知道在 Sequelize 中有没有办法做到这一点吗?谢谢
Do you know if there is a way to do this in Sequelize? Thanks
推荐答案
要包含所有关联的模型,您可以使用 all
和 nested
选项:
To include all associated models, you can use the all
and nested
options:
// Fetch all models associated with User
User.findAll({ include: { all: true }});
// Fetch all models associated with User and their nested associations (recursively)
User.findAll({ include: { all: true, nested: true }});
这篇关于如何使用 sequelize 运行递归查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文