3

I have a parse data model like...

Parent
------
children - Array of pointers to Child objects

I'm trying to create a query that says...

Find all Parents where the children array contains the specific Child object.

It's sort of the opposite of this function from the docs.

query.containedIn("playerName", ["Jonathan Walsh", "Dario Wunsch", "Shawn Simon"]);
// note you can also do this with object pointers which is EXACTLY opposite to what I want.

This will find all the players where the playerName is contained in the given array.

I want this but I want to give a value and that value to be in the array for the key.

I imagine it's something like...

query.contains("children", someChildObject);

but the docs for contains shows it only works for substrings of strings.

How would I do what I'm looking for?

1 Answer 1

3

You should use query.equalTo for key with an array type.

Try query like following:

var ChildClass = Parse.Object.extend('ChildClass');
var childObj = new ChildClass();
childObj.id = 'objId';
// you don't need to do above if you already have the object.

query.equalTo("children", childObj);
...

ref. Queries on Array Values

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

1 Comment

Ah, I didn't think equalTo would work but it seems you're right :) Thanks

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.