Reputation: 8992
I need to query my Parse.com backend for a list of objects, that have a list of pointers within those objects.
Given a pointer value, how can I query for a list of objects whose inner list of pointers contains that pointer value?
Some more detail, ObjectA contains a list of pointers, to ObjectB. When I delete ObjectB, I have cloud code that cascades this deletion. I need to query all of my ObjectA's that have ObjectB in their list of ObjectB's.
I hope this makes sense.
I have been looking at the "contain" methods for the Javascript API; Do these methods also work with keys that are arrays?
My current beforeDelete implementation is as follows.
var objectB = request.object;
var objectAQuery = new Parse.Query('ObjectA');
objectAQuery.find().then(
function (objectAArray) {
objectAArray.forEach(function (objectA) {
objectA.remove('objectBListKey',objectB);
});
Parse.Object.saveAll(objectAArray, {
success: function () {
response.success();
},
error: function (error) {
response.error(error);
}
});
},
function (error) {
response.error(error);
}
);
This code seems inefficient as its querying a ton of unnecessary ObjectA's that may not even have a pointer in their list of ObjectB's.
Upvotes: 0
Views: 381
Reputation: 1000
It seems like what you are looking for is the containedIn
function on Parse.Query
. This would allow you to query on the ObjectA class on the key of the pointer array, returning only the ObjectA instances that have the pointer you passed into the containedIn
parameter in its array of pointers.
Upvotes: 1