Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何在获取PFquery对象的同时获取PFRelation对象?_Iphone_Ios_Parse Platform_Pfquery_Pfrelation - Fatal编程技术网

Iphone 如何在获取PFquery对象的同时获取PFRelation对象?

Iphone 如何在获取PFquery对象的同时获取PFRelation对象?,iphone,ios,parse-platform,pfquery,pfrelation,Iphone,Ios,Parse Platform,Pfquery,Pfrelation,我想在从第一个查询本身检索对象时查找所有对象。请解决我的问题有一种方法可用于包含作为指针值的属性。不能对关系使用include方法。我所做的是使用一个云代码函数将我想要的结果聚合到一个JSON对象中并返回该对象 请参阅以下脚本中的fetchPostDetails函数 它获取的项目是关系对象,如标签和类似物,它们恰好是与Post类相关的User对象。还有一些注释被引用为从每个注释返回帖子的指针。fetchPostTags和fetchPostLikes方法显示如何获取这些关系并填充保存所有结果的J

我想在从第一个查询本身检索对象时查找所有对象。请解决我的问题

有一种方法可用于
包含作为指针值的
属性。不能对关系使用
include
方法。我所做的是使用一个云代码函数将我想要的结果聚合到一个JSON对象中并返回该对象

请参阅以下脚本中的
fetchPostDetails
函数

它获取的项目是关系对象,如标签和类似物,它们恰好是与
Post
类相关的
User
对象。还有一些注释被引用为从每个注释返回帖子的指针。
fetchPostTags
fetchPostLikes
方法显示如何获取这些关系并填充保存所有结果的JSON对象。您需要部署这些云代码更新,然后从iOS端将其作为一项功能进行访问。结果将作为NSDictionary返回,其中包含帖子、标签、喜欢和评论的值。Post是Post对象的数组。标记、like和注释是NSDictionary对象,它们的postId作为访问Parse对象数组的键

这样,只需对函数进行一次调用即可获得所需的结果

我已经包括了下面的一些代码作为参考,以防GitHub上的内容发生变化

 NSPredicate *predicate=[NSPredicate predicateWithFormat:@"(UserId==%@)",[defaluts objectForKey:@"objectId"]];
    PFQuery *frndquery=[PFQuery queryWithClassName:@"FriendsDetails" predicate:predicate];
    [frndquery orderByDescending:@"lastdate"];
    [frndquery whereKey:@"BlockStatus" equalTo:@"No"];
    NSArray *arrquery=[frndquery findObjects];
   for (PFObject *frndids in arr){
        PFRelation *relation=[frndids relationforKey:@"ChatRelation"];
        NSArray *arrids=[NSArray arrayWithObjects:[frndids objectForKey:@"UserId"],[frndids objectForKey:@"ConversationID"], nil];
        PFQuery *statusQuery = [relation query];
        [statusQuery orderByDescending:@"createdAt"];
        [statusQuery whereKey:@"Deletechat" notContainedIn:arrids];
        statusQuery.limit = [[NSNumber numberWithInt:1] intValue];
        NSArray *arrforrelationobjects=[statusQuery findObjects];} 
//PT命名空间中的帮助函数
变量PT={
eachItem:函数(项、回调){
var指数=0;
var promise=new Parse.promise();
var continueWhile=函数(nextItemFunction,asyncFunction){
var item=nextItemFunction();
如果(项目){
异步函数(项)。然后(函数(){
continueWhile(nextItemFunction、asyncFunction);
});
}
否则{
承诺。决心();
}
};
var nextItem=函数(){
if(索引<项目长度){
var项目=项目[索引];
索引++;
退货项目;
}
否则{
返回null;
}
};
continueWhile(nextItem,回调);
回报承诺;
},
arrayContainsItem:函数(数组,项){
//如果项位于数组中,则为True
var i=数组长度;
而(我--){
if(数组[i]==项){
返回true;
}
}
返回false;
},
ArrayContaineSotherArray:函数(数组、其他数组){
///如果其他数组中的每个项都在数组中,则为True
var i=otherArray.length;
而(我--){
if(!PT.arrayContainsItem(array,otherArray[i])){
返回false;
}
}
返回true;
},
fetchPostTags:函数(post){
return post.relation(“tags”).query().find();
},
fetchPostLikes:函数(post){
return post.relation(“likes”).query().find();
},
fetchPostComments:函数(post){
var query=newparse.query(注释);
查询。包括(“业主”);
query.equalTo(“post”,post);
返回query.find();
},
fetchPostDetails:函数(post,json){
json.tags[post.id]=[];
json.likes[post.id]=[];
json.comments[post.id]=[];
返回PT.fetchPostTags(post).then(函数(标签){
json.tags[post.id]=标记;
返回PT.fetchPostLikes(post);
}).然后(函数(likes){
json.likes[post.id]=likes;
返回PT.fetchPostComments(post);
}).然后(职能(评论){
json.comments[post.id]=注释;
json.count++;
返回Parse.Promise.as();
});
},
};

喜欢
请解决我的问题
:在frndquery中,我从frnd查询中获取pfrelation对象,同时从frnd查询中获取objec,之后我从该关系对象中重新服务数据,现在我需要在获取pfquery*frndquery对象时,我需要关系对象的详细信息我不想编写获取pfrelation对象的代码我需要获取所有详细信息(即frndquery详细信息和关系详细信息,因此我可以减少加载)。因此,请帮助我
// Helper functions in PT namespace
var PT = {

    eachItem : function (items, callback) {
        var index = 0;
        var promise = new Parse.Promise();

        var continueWhile = function(nextItemFunction, asyncFunction) {
            var item = nextItemFunction();
            if (item) {
                asyncFunction(item).then(function() {
                    continueWhile(nextItemFunction, asyncFunction);
                });
            }
            else {
                promise.resolve();
            }
        };

        var nextItem = function() {
            if (index < items.length) {
                var item = items[index];
                index++;
                return item;
            }
            else {
                return null;
            }
        };

        continueWhile(nextItem, callback);

        return promise;
    },

    arrayContainsItem : function(array, item) {
        // True if item is in array
        var i = array.length;
        while (i--) {
            if (array[i] === item) {
                return true;
            }
        }
        return false;
    },

    arrayContainsOtherArray : function(array, otherArray) {
        /// True if each item in other array is in array
        var i = otherArray.length;
        while (i--) {
            if (!PT.arrayContainsItem(array, otherArray[i])) {
                return false;
            }
        }
        return true;
    },

    fetchPostTags : function(post) {
        return post.relation("tags").query().find();
    },

    fetchPostLikes : function(post) {
        return post.relation("likes").query().find();
    },

    fetchPostComments : function(post) {
        var query = new Parse.Query(Comment);
        query.include("owner");
        query.equalTo("post", post);
        return query.find();
    },

    fetchPostDetails : function(post, json) {
        json.tags[post.id] = [];
        json.likes[post.id] = [];
        json.comments[post.id] = [];

        return PT.fetchPostTags(post).then(function(tags) {
            json.tags[post.id] = tags;
            return PT.fetchPostLikes(post);
        }).then(function(likes) {
            json.likes[post.id] = likes;
            return PT.fetchPostComments(post);
        }).then(function(comments) {
            json.comments[post.id] = comments;
            json.count++;
            return Parse.Promise.as();
        });
    },

};