I'd like to know how to make a Sequelize query to get specific posts of my blog between for example 10 and 20...
My code below is showing the last ten posts...
dbContext.post.findAll({order: 'id DESC', limit: 10 /*10,10?*/, where: {state: 1}}).success(function(posts) {
callback(posts);
});
Anthony
To do what you want, you have to combine limit
and offset
options. The offset
option lets you step over the n
number of elements you pass to it. Try that:
dbContext.post.findAll({
where: {
state: 1
},
order: 'id DESC',
offset: 10,
limit: 10
}).success(function (posts) {
callback(posts);
});
This will return will skip the first 10 elements, and return elements from 11 to 20.