Bookshelf: `fetchPage` is not a function

Created on 25 Aug 2016  路  4Comments  路  Source: bookshelf/bookshelf

I want to query records using fetchPage.

My code is this as stated in the doc:

Model.query((qb) => {
    qb.orderBy('name', 'ASC')
  }).fetchPage({
    pageSize: count ? parseInt(count) : 10,
    page: page ? parseInt(page) : 1
  }).then(providers => {
    console.log('providers', providers);
    res.json(providers);
  })

However, it always returns an error:

  fetchPage is not a function

When I checked the bookshelf lib in my node_modules, the method fetchPage already exists in the current version that I used.

Bookshelf version: ^0.9.2

Could anyone help me on this?

Much appreciated!

Update

I tried executing npm update bookshelf. No luck at yet.

docs question

Most helpful comment

I see. So I needed to declare this:

bookshelf.plugin('pagination')

before I'm going to use fetchPage. I'll try this out. Thank you!

Maybe the author can update the documentation to specify the declaration of the plugin. For the meantime, I'm closing this issue.

All 4 comments

It is an issue with the documentation. fetchPage is added by pagination plugin.

@vellotis

I'm sorry I did not follow. Can you give me a code snippet on the correct usage?

No prob. Its just an aissue with the documentation.
Look https://github.com/tgriesser/bookshelf/wiki/Plugin:-Pagination

I see. So I needed to declare this:

bookshelf.plugin('pagination')

before I'm going to use fetchPage. I'll try this out. Thank you!

Maybe the author can update the documentation to specify the declaration of the plugin. For the meantime, I'm closing this issue.

Was this page helpful?
0 / 5 - 0 ratings