Hello,
I’m looking for a solution to filter a list of objects in a relation (one-to-many) based on attribute of many side object.
I have something like
A
list of B
B
active: Boolean
I’m trying to retrieve A’s with active B’s using BackendlessDataQuery API in Android Enviroment.
Thanks.
Hi, Wakim!
Did not quite understand your situation. You class A has a list of B instances. and class B has a boolean “active” field. So you want to get those A that have at least one active instance of B?
BTW, did you check BackendlessQuery documentation:
https://backendless.com/documentation/data/android/data_basic_search.htm
https://backendless.com/documentation/data/android/data_search_and_query.htm
Thanks Anatolii,
English isn’t my main language, so let me elaborate the issue.
Right now, I’m doing a query to fetch all A’s based on a certain criteria. Along with the query, i’m using a QueryOptions to fetch all related B’s for each A.
But I want to filter the related list of B’s for just the active rows, not all B’s. As a workaround I can try to filter it in client-side, but it waste resource specially when the list is big.
Thanks.
Sorry Anatolli, i’ve commented below, instead of replying you 
Unfortunately, there is no direct way of doing this. You can only search by related objects but cannot retrieve related objects partially - either you retrieve all of the related objects or none of them.
But you can do it this way:
- Retrieve A object, read its objectId (let’s call it AobjectId).
- Create query for B objects with WhereClause like this: A[rel].id = AobjectId (where “rel” is the name of the relation in A to B objects.
You can use the documentation links I’ve shared with you in a previous comment for more information on this.
Thanks Anatolli, i’ll take a look into this workaround.