iphone - How to get the PFRelation objects while getting the PFquery objects? -


 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];    (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];}  

i want find objects when retrieve objects first query itself. please solve problem

there method can use include properties pointer values. cannot use include method relations. instead use cloud code function aggregate results want json object , return object.

see fetchpostdetails function in following script.

https://github.com/brennanmke/postthings/blob/master/parse/postthings/cloud/main.js

it fetches items relation objects such tags , likes happen user objects relations post class. there comments referenced pointer post each comment. fetchposttags , fetchpostlikes methods show how fetch relations , populate json object holding of results. need deploy cloud code update , access function ios side. results come nsdictionary values posts, tags, likes , comments. posts array of post objects. tags, likes , comments nsdictionary objects have postid key access array of parse objects.

this way 1 call function want need.

i've included of code below reference in case on github changes.

// 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 in array         var = array.length;         while (i--) {             if (array[i] === item) {                 return true;             }         }         return false;     },      arraycontainsotherarray : function(array, otherarray) {         /// true if each item in other array in array         var = 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();         });     },  }; 

Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -