objectbox-java icon indicating copy to clipboard operation
objectbox-java copied to clipboard

Support query filter for ID and property query

Open jesualex opened this issue 5 years ago • 3 comments

Hi,

I open this issue because I need to work with filters but whatever I do apart from QueryBuilder.filter().find() ignores the filter I made.

for example I need an array of ids and understand that in the case of QueryBuilder.filter().findIds() the definition explicitly says that the call ignores the filter, so try assigning QueryBuilder.filter().property(example_.id) .findLongs() but also in this way the filter is ignored , if I also try to do QueryBuilder.filter().count() the same

any solution other than going through the list?

jesualex avatar Aug 22 '18 19:08 jesualex

Sorry, query filters are only supported for regular queries (build().find(), also build().forEach()). Check the source code: https://github.com/objectbox/objectbox-java/blob/1337d56ec47303355f4d6c85630981899b713b16/objectbox-java/src/main/java/io/objectbox/query/QueryBuilder.java#L218

https://github.com/objectbox/objectbox-java/blob/1337d56ec47303355f4d6c85630981899b713b16/objectbox-java/src/main/java/io/objectbox/query/Query.java#L201

They are not used for ID queries (findIds()) property queries (property()) or anything else. This is because query filters work on the Java side (see above code snippet) and not on the database side.

What are you trying to do that can not be done with query conditions? -ut

greenrobot-team avatar Aug 27 '18 07:08 greenrobot-team

Thanks for the response @greenrobot-team, i understand

My query condition is this:

box.query().filter(request -> request.getManagements().isEmpty()).build();

In my Project the Request entity has a ToMany relation with the Management entity so, i only need the ids of the request that do not have any associated management.

I also perfectly understood the point, so if there is nothing to do in this case feel free to close the issue

regards

jesualex avatar Aug 27 '18 15:08 jesualex

Btw, we have plans to make filters more universal in the future.

greenrobot avatar Aug 27 '18 15:08 greenrobot