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

$or bug #120

Closed
sylvainlap opened this issue Oct 6, 2017 · 4 comments
Closed

$or bug #120

sylvainlap opened this issue Oct 6, 2017 · 4 comments

Comments

@sylvainlap
Copy link
Contributor

Hi,

I'm using the last version of feathers-knex.

Here is my hook.params.query:

{
    $or: [
        { firstname: { $like: "dace" },
        { lastname: { $like: "dace" },
    ],
    company: 1
}

And here is how feathers-knex transforms it:

"select "users".* from "users" where "company" = 1 or ("firstname" like 'dace') or ("lastname" like 'dace') limit 10"

As you can see, the or after the company = 1 should be a AND, not a OR.

@daffl
Copy link
Member

daffl commented Oct 7, 2017

This is probably happening in https://github.com/feathersjs/feathers-knex/blob/master/src/index.js#L90 but I'm not sure how it should be changed. Does order matter?

@sylvainlap
Copy link
Contributor Author

According to knexjs docs, the or conditions should be all wrapped into a .where().

For example:

knex('users').where(function() {
  this.where('id', 1).orWhere('id', '>', 10)
}).orWhere({name: 'Tester'})

Outputs:

select * from "users" where ("id" = 1 or "id" > 10) or ("name" = 'Tester')

@sylvainlap
Copy link
Contributor Author

I created a PR for this issue: #122

@daffl
Copy link
Member

daffl commented Oct 19, 2017

Closed via #122

@daffl daffl closed this as completed Oct 19, 2017
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