Pratik Thaker
Pratik Thaker

Reputation: 657

How to query a field in a related object in a ParseQuery

I'm using Parse.com and I am running a query that obtains objects in a many-to-many relational table (call this table 'RelationTable'). Obviously this table has links to objects in another table (let's call this SubObject). Now, from this query, I need to filter results by searching on a field contained within the SubObject (call this SearchField).

Any ideas on how to do this? I already have the includeKey and am trying the '.' operator in SQL to access a field in the subclass, but it's not working. Below is the code I have so far:

ParseQuery<ParseObject> query = ParseQuery.getQuery("RelationTable);
query.include("subObject"); //subObject is field name where SubObject is stored. Note CAPS difference
query.whereContains("SubObject.SearchField", searchString);

Upvotes: 0

Views: 297

Answers (1)

Baptiste Truchot
Baptiste Truchot

Reputation: 341

You can create a subquery on the user object, and use whereMatchesQuery on your RelationTable query :

ParseQuery<ParseObject> query = ParseQuery.getQuery("RelationTable);
query.include("subObject"); 

ParseQuery<ParseObject> innerQuery = ParseQuery.getQuery("SubObject");
innerQuery.whereContains("SearchField", searchString);

query.whereMatchesQuery("subObject", innerQuery);

Upvotes: 1

Related Questions