Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paginate option for a feathers-sequelize service is not working as expected #186

Closed
katerina-semikina opened this issue Jan 12, 2018 · 5 comments
Labels

Comments

@katerina-semikina
Copy link

Steps to reproduce

If paginate option is set to false for a service, count query is still created while calling find service method.

Example:

const Model = require('./models/mymodel');
const service = require('feathers-sequelize');

const paginate = false;
app.use('/messages', service({ Model, paginate }));

Expected behavior

Model.findAll is invoked instead if Model.findAndCountAll.

Actual behavior

Model.findAndCountAll is invoked. Extra count query is executed.

The reason is the following case:

  • Service initialization:

If options.paginate is false, then this.paginate becomes equal to {}.

this.paginate = options.paginate || {};

link to the line

  • find method:

If params.paginate is undefined, then this.paginate value is assigned to paginate variable, so paginate becomes equal to {}.

const paginate = (params && typeof params.paginate !== 'undefined') ? params.paginate : this.paginate;

link to the line

  • _find method:

If paginate is {}, then the condition is true, so Model.findAndCountAll is called.

    if (paginate) {
      return Model.findAndCountAll(q).then(result => {
        // ...
      }).catch(utils.errorHandler);
    } else {
      return Model.findAll(q).then(result => {
        // ...
      }).catch(utils.errorHandler);
    }

link to the line

System configuration

Feathers-sequelize version: 2.3.0

NodeJS version: 8.1.2

Operating System: macOS 10.12.6

@ninique
Copy link

ninique commented Feb 6, 2018

Just ran into this issue myself. If I turn off pagination in a hook by setting params.paginate = false there it works. But if I turn it off when initializing the service it does not.

@amaanm
Copy link

amaanm commented Mar 20, 2018

I can confirm that I am also experiencing this, and I successfully used the same fix as @katerina-semikina

@ninique the hook fix also works, since the hook param for paginate being false is correctly checked in the find method.

@alex-friedl
Copy link
Contributor

I ran into this myself.

The issue is line 18 in index.js
this.paginate = options.paginate || {};

Removing the default `|| {}' should fix the issue.

@daffl
Copy link
Member

daffl commented Jun 7, 2018

That should do it. Pull request welcome.

@alex-friedl
Copy link
Contributor

Opened #217

@daffl daffl closed this as completed in #217 Jun 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants