[英]Sequelize: join tables beyond first degree relationship
I have the following relationships: 我有以下关系:
User
has Subscription
User
已Subscription
Subscription
has Subject
Subscription
有Subject
Subject
has Lesson
Subject
有Lesson
If this was a multi-demensional array, it would look like this: 如果这是一个多维数组,则看起来像这样:
`User` =>
(`Subscription` =>
`Subject` =>
(`Lesson`, `Lesson`),
`Subscription` =>
`Subject` =>
(`Lesson`, `Lesson`)
, ...)
How do I query the full dataset preserving this structure using Sequelize? 如何使用Sequelize查询保留此结构的完整数据集? If I had to write it in "sequelize pseudo-code", I would have something like:
如果必须用“伪伪码序列化”来编写,则可能会出现以下内容:
seq.User.findAll({
include[seq.Subscription.findAll({
include[seq.Subject.findAll({include: [seq.Lesson]}) ...
This should be about what you'd need. 这应该与您的需求有关。 You nearly had the idea/flow in your pseudo code.
您几乎在伪代码中有了想法/流程。 They may be a more efficient way to write this/do this?
他们可能是写/做这个的更有效的方法吗? But this should work
但这应该工作
seq.User.findAll({ where: {}, include: [{ model: seq.Subscription, include: [{ model: seq.Subject, include: [{ seq.Lesson }] }] }] }).then(function(responseFromDB) { handle callback });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.