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

Unable to fetch right results with a complex query #28

Closed
hdattada opened this issue Jan 20, 2017 · 1 comment
Closed

Unable to fetch right results with a complex query #28

hdattada opened this issue Jan 20, 2017 · 1 comment

Comments

@hdattada
Copy link

hdattada commented Jan 20, 2017

I am trying to fetch results using a complex query which is similar to the one below. I am not sure how to design it to get the right results
(FIELDA = 'A' or FIELDA = 'B' or FIELDA = 'C') AND (FIELDB ='AA' or FIELDB = 'BB' or FIELDC = 'CC') AND FIELDC !='123' AND FIELDC !='345' AND FIELDC !='789'

The query I designed is as below

query = query.where('FIELDA', '=', 'A')
query = query.or('FIELDA' ,'=', 'B')
query = query.or('FIELDA', '=' ,'C')
query = query.or('FIELDB', '=', 'AA')
query = query.or('FIELDB', '=', 'BB')
query = query.or('FIELDB', '=', 'CC')
query = query.and('FIELDC', '!contains', '123')
query = query.and('FIELDC', '!contains', '345')
query = query.and('FIELDC', '!contains', '789')

I am not sure if I am doing anything wrong here

@krmorse
Copy link
Contributor

krmorse commented Jan 26, 2017

You need to build it up from the inside out.

var fieldAQuery = query.where('FIELDA', '=', 'A').or('FIELDA' ,'=', 'B').or('FIELDA', '=' ,'C');
var fieldBQuery = query.where('FIELDB', '=', 'AA').or('FIELDB', '=', 'BB').or('FIELDB', '=', 'CC');
var fieldCQuery = query.where('FIELDC', '!contains', '123').and('FIELDC', '!contains', '345').and('FIELDC', '!contains', '789');

And then once you have those parts you can and them together.

var finalQuery = fieldAQuery.and(fieldBQuery).and(fieldCQuery);

On the plus side, we are currently working on supporting an additional "in" operator for many fields in WSAPI which will greatly simplify these queries in the future.

@krmorse krmorse closed this as completed Jan 26, 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