0

I'm trying to query using each elements on the array as the constraint, but so far its has only given me one result.

Here is the array:

["C44","C43","C45","C117"]

Here what I have:

{var TestObject = Parse.Object.extend("TestObject");
    var query = new Parse.Query(TestObject);
    query.get("W7yuUsbbav", {
        success: function(testObject) {
            var subjectArray = testObject.get("subjects");


            for (i = 0; i < subjectArray.length ; i++ ){

                console.log(subjectArray[i]);
                var query = new Parse.Query("Subjects");
                query.equalTo("subCode", subjectArray[i]);
                query.find({
                    success: function(results) {
                        $scope.$apply(function() {
                            $scope.subjects1 = results.map(function(obj) {
                                return {subCode: obj.get("subCode"), subName: obj.get("subName"),  subDesc: obj.get("subDesc")};
                            });
                        });
                    },
                    error: function(error) {
                    }
                });
            }

        },
        error: function(object, error) {
            // The object was not retrieved successfully.
            // error is a Parse.Error with an error code and message.
        }
    });}

1 Answer 1

1

You can use the containedIn property of query.

var sampleId = "W7yuUsbbav";
var query1 = new Parse.Query("TestObject");
query1.get(sampleId).then(function (testObject) {

    // Success
    var subjectArray = testObject.get("subjects");

    var query2 = new Parse.Query("Subjects");
    query2.containedIn("subCode", subjectArray);

    return query2.find();

}).then(function (subjectObjects) {

    // Success
    // results is an array of objects

}, function (error) {

    // Error

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

3 Comments

Thanks, that got it working. This is the parse promises right? I was just reading up it but its was taking a while to figure it out.
Yes, promise notation is far more useful in creating chained queries. Please up-vote my post if I solved your issue!
As much as I want to I can't, says I need 15 rep before I can do stuff. I will when I'm able to.

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.