在续集是有可能使用嵌套预加载分页嵌套请求?
我正在使用嵌套的热切加载 funcionality,这是一个续集的例子:
User.findAll({ include: [{ model: Tool, as: 'Instruments', include: [{ model: Teacher, where: { school: "Woodstock Music School" }, required: false }] }] }).then(function(users) { /* ... */ })
想象一下,你想要做一个endpoint
“总结”,你想包括Teacher model
,但只有前三个结果
有可能只使用嵌套的预先加载?
Sequelize提供了一种方法来达到这个目的?
在尝试了很多东西之后,我得出了不能直接做的结论。
您可以使用教师模型的限制和偏移量
User.findAll({ include: [{ model: Tool, as: 'Instruments', include: [{ model: Teacher, where: { school: "Woodstock Music School" }, limit: 3, required: false } ] } ] }).then(function (users) { /* ... */ })