我的情况包括使用与关系连接的PFObject,我想使用本地数据存储添加到关系。
所以,我有一个创建主对象的屏幕,并将其正确保存到数据存储和服务器中:
// Save User
PFObject *parseUser = [PFObject objectWithClassName:@"Users"];
parseUser[@"name"] = name;
parseUser[@"uuid"] = userUuid;
[parseUser saveEventually];
// Save List
PFObject *parseList = [PFObject objectWithClassName:@"Lists"];
parseList[@"name"] = newList.listName;
parseList[@"uuid"] = newList.listUuid;
[parseList saveEventually];
[parseUser pinInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (succeeded) {
// Create relation
PFRelation *relation = [parseUser relationForKey:@"listAccess"];
[relation addObject:parseList];
[parseUser saveEventually];
}
}];
[parseList pinInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (succeeded) {
// Create relation
PFRelation *relation = [parseList relationForKey:@"sharedWith"];
[relation addObject:parseUser];
[parseList saveEventually];
}
}];
所以这部分有效。这让我有点想弄清楚,但它确实有效。创建用户和列表。设置两者的关系然后保存。容易。
转到问题区域:
// Save List
PFObject *parseList = [PFObject objectWithClassName:@"Lists"];
parseList[@"name"] = newList.listName;
parseList[@"uuid"] = newList.listUuid;
[parseList saveEventually];
PFQuery *query = [PFQuery queryWithClassName:@"Users"];
[query fromLocalDatastore];
[query whereKey:@"uuid" equalTo:[User instance].userUuid];
[[query findObjectsInBackground] continueWithBlock:^id(BFTask *task) {
if (task.error) {
NSLog(@"Error: %@", task.error);
return task;
}
PFObject *user = [task.result objectAtIndex:0];
// Create relation
PFRelation *relation = [user relationForKey:@"listAccess"];
[relation addObject:parseList];
[user saveEventually];
PFQuery *relationQuery = [relation query];
[[relationQuery findObjectsInBackground] continueWithBlock:^id(BFTask *task) {
NSLog(@"resutls: %@", task.result);
return task;
}];
[parseList pinInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (succeeded) {
// Create relation
PFRelation *relation = [parseList relationForKey:@"sharedWith"];
[relation addObject:user];
[parseList saveEventually];
}
}];
return task;
}];
所以我想我在这里做的是从本地数据存储中抓取用户并添加另一个关系。但实际上,这实际上只是将parseList保存为用户关系。用户无法在数据存储区或服务器中进行更改。
我尝过的其他事情:
感谢您的帮助。
修改: 通过查询和关系抓取,我得到一些奇怪的数据信息。
所以,首先,当搜索它时,关系是空的:
estimatedData 0 - 名字 - 比尔奈 1 - listAcces - 没有摘要 价值 - PFRelation knownObjects - 0个对象 2 - uuid - 长字符串是uuid
所以这与服务器的东西相匹配,除了关系之外。但是,当我查询关系并记录它时,我得到了这个: 结果:( " {\ n name = Okkkkk; \ n sharedWith = \"用户> \&#34 ;; \ n uuid = \" D8174D80-4F08-4B25-9B72-F8E00CF19DDB \&#34 ;; \ n}" )
所以查询它,它就在那里,但这种关系并不存在?