Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

in sequelize is it possible to paginate the Nested request using Nested eager loading?

I'm using the Nested eager loading funcionality, this is the sequelize example:

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

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

It is possible using only the Nested eager loading?

Sequelize provides a way to achieve this purpose?

like image 437
emilioriosvz Avatar asked Mar 19 '16 13:03

emilioriosvz


People also ask

What is eager loading Sequelize?

Sequelize eager loading is a way to fetch data from multiple tables that have relations between each other. When you use the eager loading technique, the generated SQL query will have one or more JOIN clauses.

How does pagination work in node JS?

Pagination in NodeJS is defined as adding the numbers to identify the sequential number of the pages. In pagination, we used to skip and limit for reducing the size of data in the database when they are very large in numbers.

What is Sequelize offset and limit?

Paginating records with Sequelize comes down to including specific properties in a query object that we then pass to the model's . findAll() method. The object has two properties - offset and limit - which indicate respectively how many records to skip and how many to take.


1 Answers

After trying many things, I came to the conclusion that it can not do directly.

like image 80
emilioriosvz Avatar answered Sep 24 '22 08:09

emilioriosvz