所以现在我有两节课。 User类和UserUpdates类。 UserUpdates类用于处理friendRequests和朋友,以及什么不是。我的UserUpdates类中有一个名为friendsArray
的字段,我想在我的User类中有一个名为friendsArray
的字段,它只指向UserUpdates friendsArray
所以我没有做一个单独的查询。
总而言之,我想要完成的是在我的User类中有一个字段,它会自动更新或指向另一个类中的friendsArray
(UserUpdates)
friendsArray只是一个字符串数组,是用户名
如何使用parse的api完成此操作?
答案 0 :(得分:1)
无法指向另一个对象的属性;你只能指向包含该属性的对象(friendsArray)。
如果你想要完成的是从UserUpdates类中轻松获取friendsArray,那么如果User类有一个指向UserUpdates对象的指针,你就可以这样做:
PFQuery *userQuery = [PFUser query];
// add constraints to get the correct user
[userQuery includeKey:@"UserUpdates"]; // ensures the UserUpdates object is downloaded with the User object
NSArray *results = [userQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
PFUser *theUser = [objects lastObject]; // If the constraints returns only 1 object
PFObject *userUpdates = theUser[@"UserUpdates"];
NSArray *friends = userUpdates[@"friendsArray"]; // Now you have the friends array
}];
可能可以像这样链接最后一次调用,但我不确定。试试吧:
NSArray *friends = theUser[@"UserUpdates"][@"friendsArray"];
答案 1 :(得分:0)
简单地说:你不能。
但是我得到了你想要完成的东西,而且这种方法效果不好,只要一个课程为每个用户提供多个字段,就更好了。
我用Parse创建了一个简单的友情系统,这种系统过于复杂,我建议你在提供系统泄漏方面要小心谨慎,尽量保持一切尽可能简单。