Nested queries using javascript in cloud code (Parse.com)

前端 未结 3 653
予麋鹿
予麋鹿 2020-12-31 16:30

Is it possible to do nested queries in cloud code?

I want to be able to do something like

var adList = [];
var query2 = new Parse.Query(\"QR\");
var          


        
3条回答
  •  执念已碎
    2020-12-31 16:49

    I think the below code might help someone,

    var adList = [];
    var query2 = new Parse.Query("QR");
    var query = new Parse.Query("Campaigns");
    query.equalTo("isFeatured", true);
    
    query.find().then(function(results) {
        var _ = require('underscore');
        var promise = Parse.Promise.as();
        _.each(results, function(resultObj) { 
            var ad = [];
            ad.push(resultObj.get("Type"));    //Adds "Type" to the ad array
            ad.push(resultObj.id);     //gets the objectID and appends it to the arrayy
    
            //second INNER QUERY
            query2.equalTo("abc", true);
            adList.push(ad);
            return query2.first().then(function(results) {
                adList.push(5);
            });
        });
        return promise;
    }).then(function() {
        response.success(adList);
    }, function (error) {
        response.error("Error "+error.message);
    });
    

提交回复
热议问题