In my application the user creates a PFObject in the alarm class that has a relation to the current user. I would like to retrieve it and edit it.
Adding the object:
PFUser *user = [PFUser currentUser];
PFObject *alarm = [PFObject objectWithClassName:@"Alerts"];
alarm[@"Active"] = @YES;
alarm[@"ActionWasCompleted"] = @NO;
alarm[@"Time"] = _alarmTime;
PFRelation *relation = [user relationForKey:@"user"];
[relation addObject:user];
[alarm saveInBackground];
Retrieving the user specific object and editing it:
PFQuery *query = [PFQuery queryWithClassName:@"Alerts"];
[query whereKey:@"user" equalTo:[PFUser currentUser]];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
NSLog(@"Successfully retrieved %d objects.", objects.count);
[[objects objectAtIndex:0] setObject:@YES forKey:@"ActionWasCompleted"];
} else {
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
Now I have used relational queries before I haven't edited them, but I cant even seem to retrieve the objects in the alarm class related to the current user. Let alone edit the object. I don't know what I'm doing wrong.
All I would like to do is create a PFObject that is specific to the user, retrieve it and edit it.
If you have any suggestions I'm all ears! Thanks!
EDIT: I figured out how to save the queried object using
[PFObject saveAllInBackground:objects];
But I'm still unable to retrieve objects related to the current user.