Skip to content

Fix count query when using params.knex - #145

Merged
daffl merged 1 commit into
feathersjs:masterfrom
omeid:master
Feb 24, 2018
Merged

daffl merged 1 commit into
feathersjs:masterfrom
omeid:master

Conversation

@omeid

@omeid omeid commented Feb 24, 2018

Copy link
Copy Markdown
Contributor

Fixes #121

@daffl
daffl merged commit 2578dc1 into feathersjs:master Feb 24, 2018
@daffl

daffl commented Feb 24, 2018 •

Copy link
Copy Markdown
Member

Great, thank you! Released as v3.0.3

@omeid

omeid commented Feb 24, 2018 •

Copy link
Copy Markdown
Contributor Author

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

@omeid

omeid commented Feb 25, 2018

Copy link
Copy Markdown
Contributor Author

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

@cjbland

cjbland commented Jan 2, 2019 •

Copy link
Copy Markdown

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: https://github.com/feathersjs-ecosystem/feathers-knex/blob/e7f04f34d45be5c00ca7848fac1c51c9ac36703c/lib/index.js#L193

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