This is a migrated thread and some comments may be shown as answers.

Filtering data requests

1 Answer 42 Views
JavaScript SDK
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kevin
Top achievements
Rank 1
Kevin asked on 01 Mar 2016, 04:08 PM

i am trying to download data from the back-end services with a number of conditions that must be satisfied.

i achieved this in swift for the ios version of the app using a NSPredicate

request.predicate = NSPredicate(
    format: "CreatedByName == %@ OR (To ==%@ AND CreatedByName == %@)",
    userOne,
    userID,
    UserTwo
)

i need a similar solution for the javascript api. my problem is knowing hopw to combine the AND and OR. I have Tried:

var query = new Everlive.Query();
query.where().and()
        .eq('CreatedBy', customerName)
        .eq('To', to)
        .done();

 

But how do i add the or.

 

It is a messing section of an app the admin can chat with any end user but the end user can only reply to the admin or or send messages to the admin so my query needs to reflect that in a chat stream. ie. is (created by admin AND is to userA ) OR (is created by userA)

1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 02 Mar 2016, 03:18 PM

Hello Diego,

With 'and' and 'or' querying methods you create complex condition. The complex conditions are terminated with the done() method. You can think of calling and() .... done() as the brackets "()" in mathematics - anything that is between them will be evaluated first.

The example in question -> "(created by admin AND is to userA ) OR (is created by userA)" will look like:

var query = new Everlive.Query();
query.where()
    .or()
        .and()
            .eq('CreatedBy', admin)
            .eq('To', userA)
        .done()
        .eq('CreatedBy', userA)
    .done();

 
The last done() can be omitted as there are no following conditions (but this way it looks clearer).


Let me know if this has worked for you.

Regards,
Martin
Telerik
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
Tags
JavaScript SDK
Asked by
Kevin
Top achievements
Rank 1
Answers by
Martin
Telerik team
Share this question
or