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

IN operator similar to NSPredicate's "fieldName IN %@" #1280

Closed
virl opened this issue Jul 9, 2015 · 5 comments
Closed

IN operator similar to NSPredicate's "fieldName IN %@" #1280

virl opened this issue Jul 9, 2015 · 5 comments

Comments

@virl
Copy link

virl commented Jul 9, 2015

Greetings.
I need to retrieve objects from realm whose field doesn't have any of the values presented in code-supplied List.

In Realm for iOS I do that like this: [SLLocation objectsInRealm:realm where:@"date > %@ AND NOT (signalId IN %@)", fromDate, signalIds]

How to do that in Realm for Java?

@kneth
Copy link
Member

kneth commented Jul 10, 2015

Yes, an IN like operator in queries can be useful. It is fairly simple workaround:

RealmQuery<SLLocation> query = realm.where(SLLocation.class);
for (int id : signalIds) {
    query = query.or().equalsTo("signalId", id);
}

Your request is similar to #841.

@virl
Copy link
Author

virl commented Jul 10, 2015

Thanks. Will it work when signalIds array is pretty large (2-3 thousands of items)?

@virl virl closed this as completed Jul 10, 2015
@kneth
Copy link
Member

kneth commented Jul 13, 2015

Yes, it should work (we have a unit test with 1024 conditions).

@virl
Copy link
Author

virl commented Jul 13, 2015

Thanks.

@tgoyne
Copy link
Member

tgoyne commented Jul 13, 2015

The IN operator in iOS currently just does the same thing of looping over the array and building up a chained OR/equalsTo, so you should see identical performance.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants