Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse Cloud Query array contains value

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?

like image 341
Fogmeister Avatar asked Dec 03 '25 09:12

Fogmeister


1 Answers

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

like image 76
eth3lbert Avatar answered Dec 06 '25 13:12

eth3lbert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!