1

I'm confused how to use parses cloud code to perform a nested query or relational query.

What I want to do is get all objectId's from table1 that match a criteria.

Then use those objectId's to query table2 and check for query2.equalTo("table2ID", table1[i].objectId);

Then get the count of all object's that match that query2 and if < X return table1[i].

1 Answer 1

1

Since you really want to count members of table2, make that your main query...

var query = new Parse.Query("Table2");

The thing you want to count is table2 elements that are associated with table1 elements such that the table1 element matches some criterion...

var innerQuery = new Parse.Query("Table1");
innerQuery.equalTo("someKey", "someValue");  // some criterion
query.matchesQuery("table2ID", innerQuery);

Now, get a count....

query.count().then(count => /* do something if count > X? */);

It's important that the data is setup properly for this:

  1. When initializing table2 elements, you need to place real references to table1 objects (not just strings representing ids).

    myTable1Object = // whatever
    myTable2Object.set("table2ID", myTable1Object.id);  // WRONG
    myTable2Object.set("table2ID", myTable1Object);     // correct
    
  2. I think the made-up names you used in your question might also add some confusion. A real pointer to table1 is better called "table1". That is, not table2 (which is the table where it appears) and no "ID" suffix which implies it violates point #1 above.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.