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

Fix count query when using params.knex #145

Merged
merged 1 commit into from
Feb 24, 2018

Conversation

omeid
Copy link
Contributor

@omeid omeid commented Feb 24, 2018

Fixes #121

@daffl daffl merged commit 2578dc1 into feathersjs-ecosystem:master Feb 24, 2018
@daffl
Copy link
Member

daffl commented Feb 24, 2018

Great, thank you! Released as v3.0.3

@omeid
Copy link
Contributor Author

omeid commented Feb 24, 2018

Should note that until knex/knex#51 is addressed, this will break when using with .distinct() :(

@omeid
Copy link
Contributor Author

omeid commented Feb 25, 2018

A workaround is to use a sub-query when doing distinct, so SELECT * FROM (SELECT .....) and then the count would work fine.

@cjbland
Copy link

cjbland commented Jan 2, 2019

I don't mean to revive an old PR, but I was hoping @omeid could give a little more details on your workaround? If the table's id column does not exist as part of the distinct clause, the count will not work. This is the issue I'm running into right now because of this line:

.count(`${this.table}.${this.id} as total`);

Here is a snippet from my hook:

const value = params.query['$distinct'];
delete params.query['$distinct'];
context.params.knex =context.service.createQuery(params).clearSelect().distinct(value);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants