odata-query icon indicating copy to clipboard operation
odata-query copied to clipboard

'not' operator is being applied only to the first condition with and/or operators

Open relair opened this issue 5 years ago • 3 comments

I've tried to use the new 'not' operator for some of my logic while I noticed it doesn't get applied correctly - it is applied 'not' to the first condition instead of the whole group

It loolks like the example presents the issue as well: const filter = { not: { and:[ {SomeProp: 1}, {AnotherProp: 2} ] } };

buildQuery({ filter }) => '?$filter=(not (SomeProp eq 1) and (AnotherProp eq 2))'

It should be => '?$filter=(not ((SomeProp eq 1) and (AnotherProp eq 2)))'

as otherwise it would be considered as (not SomeProp eq 1) and (AnotherProp eq 2)

relair avatar Oct 02 '19 15:10 relair

I can't implement { not: { prop: { in: [...] } } } pattern. I couldn't succeed to use NOT with IN operator.

hakan-bilgin avatar Dec 06 '19 13:12 hakan-bilgin

bump

regexer-github avatar Feb 25 '20 12:02 regexer-github

As of the current version (09/2022), brackets are always put around what follows not, see https://github.com/techniq/odata-query/blob/master/src/index.ts#L567-L569 So this issue can probably be closed?

@hakan-bilgin I do exactly that and it works with the current version.

Note that the generated $filter is lacking a required whitespace, which might be an issue depending on who parses the filter, I opened #110 for that.

jods4 avatar Sep 05 '22 12:09 jods4