olavim / objection-cursor

Cursor based pagination plugin for Objection.js
MIT License
30 stars 8 forks source link

remaining returns 0 #10

Closed idododu closed 5 years ago

idododu commented 5 years ago
// index.js line #268

return this.clone().resultSize().then(rs => {
    rs = parseInt(rs, 10);
        // below line cause remaining always be 0, because rs is equal to models.length
    const remaining = rs - models.length;
    setIfEnabled('remaining', remaining);
    setIfEnabled('remainingBefore', before ? remaining : total - rs);
    setIfEnabled('remainingAfter', before ? total - rs : remaining);
    setIfEnabled('hasMore', remaining > 0);
    setIfEnabled('hasPrevious', (before && remaining > 0) || (!before && total - rs > 0));
    setIfEnabled('hasNext', (!before && remaining > 0) || (before && total - rs > 0));
});
olavim commented 5 years ago

You can look at this passing test for proof that this isn't true: https://github.com/olavim/objection-cursor/blob/master/test/cursor.js#L121

models.length is the amount of rows returned by the query. rs is the amount of rows that the query would produce without limit and offset applied. See https://vincit.github.io/objection.js/api/query-builder/other-methods.html#resultsize.

However, have you encountered a case where remaining is equal to 0 when it shouldn't?

olavim commented 5 years ago

closing as stale