0
votes

Using Parse, I've created a column that should contain PFObjects in my User class. I'm able to fetch the current user just as I used to and to update every info of it, but the PFObject column. I don't know if a PFObject can't be stored like that and should only be referenced or if I'm just saving it the wrong way. Here's the code:

  PFObject *object = [PFObject objectWithClassName:@"User" dictionary:
   [NSMutableDictionary dictionaryWithObjectsAndKeys:currentPlace.identifier,
    [NSNumber numberWithFloat:newRating], nil]];

  [PFUser currentUser][@"rated_places"] = object;
  [[PFUser currentUser] saveInBackground];
2
This should work if the column is of type Pointer to the User class, do you get any error messages? Best to do for now is to use the saveInBackgroundWithBlock and log the error object that gets passed into the callback to see if you receive any error while saving it and add the results to your questionBjörn Kaiser
Thanks @BjörnKaiser, I will try that!vyudi

2 Answers

1
votes

Subclass PFUser. Add PFRelation. use addObject to setup relationship between PFUser and some other object. If you need one-to-one, then you could simply use a dynamic property (Pointer):

@property (nonatomic) MyObject* object;

and in implementation file you simply declare property as dynamic:

@dynamic object;

Use subclasses, this makes life so much easier than this dictionary bullshit.

Reference:

  1. https://parse.com/docs/ios/api/Classes/PFRelation.html#//api/name/addObject:
  2. https://parse.com/docs/ios/api/Protocols/PFSubclassing.html
0
votes

As explained by BjörnKaiser, what I should actually do is:

  1. Create a different class for the PFObject
  2. Keep a reference to it in the User class, using the type Pointer

Here is how it worked for me:

NSMutableDictionary *dic = [NSMutableDictionary new];
  dic[currentPlace.identifier] = [NSNumber numberWithFloat:newRating];


  PFObject *object = [PFObject objectWithClassName:@"Rating" dictionary:dic];
  [object saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
    if (!error) {
      [PFUser currentUser][@"rated_places"] = object;
      [[PFUser currentUser] saveEventually];
    }
  }];