In the sequel, is it possible to split a request into a subquery using a subload?

I use the functional loading of nested intolerance , this is an example of a continuation:

User.findAll({ include: [{ model: Tool, as: 'Instruments', include: [{ model: Teacher, where: { school: "Woodstock Music School" }, required: false }] }] }).then(function(users) { /* ... */ }) 

Imagine you want to make an endpoint 'summary', and you want to include the Teacher model , but only the first three results

Can I use only subloading?

Does Sequelize provide a way to achieve this?

+5
source share
2 answers

After many attempts, I came to the conclusion that he cannot do it directly.

+1
source

You can use restriction and bias with the teacher model

  User.findAll({ include: [{ model: Tool, as: 'Instruments', include: [{ model: Teacher, where: { school: "Woodstock Music School" }, limit: 3, required: false } ] } ] }).then(function (users) { /* ... */ }) 
0
source

Source: https://habr.com/ru/post/1245381/


All Articles