我正在使用解析框架,并想知道如何查询位于PFUser表中的列。
以下是一些示例代码:
//Adds athlete_id column to roster table
PFObject *roster = [PFObject objectWithClassName:@"Roster"];
roster[@"athlete_id"] = answer;
[roster save];
//Adds the rosters objectId to an array (athlete_id) in the User table.
PFUser *currentUser = [PFUser currentUser];
[currentUser addObject:roster.objectId forKey:@"athlete_id"];
[currentUser saveInBackground];
使用上面的代码最终在名为" athlete_id"的列中的User类中获取一个objectsID数组。
我实际上从User类检索此数组时遇到问题。以下是我试图从用户那里获取数组的方法:
FQuery *query = [PFUser query];;
[query whereKey:@"username" equalTo:[PFUser currentUser].username];
[query whereKeyExists:@"athelete_id"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
NSLog(@"athlete %@", objects);
} else {
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
我想获取当前用户的athlete_id列中包含的数组,但此查询中的objects数组为空。
答案 0 :(得分:3)
您不需要查询。
这样做:
NSString *athleteId = [[PFUser currentUser] objectForKey:@"athelete_id"];
NSLog(@"The athlete id is %@", athleteId);