因此,我很难理解PFRelation是如何保存的,我有以下代码:
PFUser *user = [PFUser currentUser];
PFRelation *relation = [user relationForKey:@"likes"];
[relation addObject:post];
[user saveInBackground];为什么更新用户(即用户saveInBackground )更新该用户的PFRelation字段“喜欢”?这是使用单个API调用还是relation : post;还需要一个API调用?
任何帮助都将不胜感激。
谢谢
发布于 2015-01-12 06:26:23
在您的示例中,在情况下使用了1 API请求。
直接从PFObject的Parse.com看一看
// Create the post
PFObject *myPost = [PFObject objectWithClassName:@"Post"];
myPost[@"title"] = @"I'm Hungry";
myPost[@"content"] = @"Where should we go for lunch?";
// Create the comment
PFObject *myComment = [PFObject objectWithClassName:@"Comment"];
myComment[@"content"] = @"Let's do Sushirrito.";
// Add a relation between the Post and Comment
myComment[@"parent"] = myPost;在这里,您正在为PFObject设置属性或属性,但是在保存它之前不会发生任何事情,您可以对对象做任何事情,比如更改它、更新它,这并不重要,但是从后端的角度来说,它不会更新,除非您告诉它哪种保存是起作用的:
[myComment saveInBackground];简而言之,您可以一整天添加关系、指针和大量参数,但是在您告诉它发生之前什么都不会发生: saveInBackground;
因为您使它与用户直接相关,所以它将其保存到该用户,因为是您告诉它的。因为您为用户指定了一个关系,所以一旦您保存了用户属性,该关系也将被保存。然而,这并不会创建更多的API请求。
https://stackoverflow.com/questions/27890110
复制相似问题