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

Bug: Query customization doesn't apply to the count SQL query #120

Closed
mikeconley12 opened this issue Oct 5, 2020 · 4 comments
Closed

Bug: Query customization doesn't apply to the count SQL query #120

mikeconley12 opened this issue Oct 5, 2020 · 4 comments

Comments

@mikeconley12
Copy link

I created a reproduction repository: https://github.com/mikeconley12/feathers-objection .
See the changes: master...mikeconley12:master

Steps to reproduce

  1. git clone https://github.com/mikeconley12/feathers-objection.git
  2. cd feathers-objection/
  3. npm i
  4. DEBUG=knex:query npm run example
  5. Open http://localhost:3030/todos?text=foo in a browser

In your terminal, you should see the following:

  knex:query select count(`todos`.`id`) as `total` from `todos` where `text` = ? undefined +5s
  knex:query select `todos`.* from `todos` where `text` = ? and `complete` = ? limit ? undefined +3ms

The first SQL query doesn't have the `complete` = ? condition, but the second SQL query has this condition.

@dekelev
Copy link
Member

dekelev commented Oct 17, 2020

Please open bugs with informative description and examples.

@dekelev dekelev closed this as completed Oct 17, 2020
@mikeconley12
Copy link
Author

I'm sorry if I'm not clear. Let me explain.

I customize the query in my example (this is an undocumented feature, but the documentation says: "It works like the Knex service adapter", and the Knex service adapter has customizing the query feature).

But my modifications to the query don't apply to the count SQL query. See logs:

  knex:query select count(`todos`.`id`) as `total` from `todos` where `text` = ? undefined +5s
  knex:query select `todos`.* from `todos` where `text` = ? and `complete` = ? limit ? undefined +3ms

I think the problem may be this:

You use params.objection here,

const q = params.objection || this.createQuery(params);

But in the count query, you don't use params.objection

const countQuery = this._createQuery(params);

@dekelev
Copy link
Member

dekelev commented Oct 17, 2020 via email

@mikeconley12
Copy link
Author

Thanks for the answers!

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

No branches or pull requests

2 participants