Reputation: 171
I am using the parse framework and would like to know how I can query a column that is located in the PFUser table.
Here is some example code:
//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];
With the above code end up getting an array of objectsID's within the User class in a column named "athlete_id".
Im having a problem actually retrieving this array from the User class. Here is how I am attempting to get the array from the 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]);
}
}];
I want to grab the array that is contained in athlete_id column for the current user, but the objects array is empty on this query.
Upvotes: 0
Views: 1923
Reputation: 3350
You don't need a query.
Just do this:
NSString *athleteId = [[PFUser currentUser] objectForKey:@"athelete_id"];
NSLog(@"The athlete id is %@", athleteId);
Upvotes: 3