0

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.

1 Answer 1

1

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.

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

1 Comment

This was it, i had something wrong with my logic when i used this. Once corrected it started to work! thank you.

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.