I am trying to get my head around PFRelation in parse. I have a class called "girlBio" that stores information about girls and a class called "stuff" that stores information about items. code below:
PFObject *item = [PFObject objectWithClassName:@"stuff"];
item[@"Name"] = @"PS3";
PFObject *girl = [PFObject objectWithClassName:@"girlBio"];
girl[@"Name"] = @"Jessica";
PFObject *girl2 = [PFObject objectWithClassName:@"girlBio"];
girl2[@"Name"] = @"Cindy";
PFRelation *relation = [item relationForKey:@"owners"];
[relation addObject:girl];
[relation addObject:girl2];
[item saveInBackground];
--------------------------------- update also tried this -------------------------
PFObject *item = [PFObject objectWithClassName:@"stuff"];
item[@"Name"] = @"PS3";
PFObject *girl = [PFObject objectWithClassName:@"girlBio"];
girl[@"Name"] = @"Jessica";
[item saveInBackground];
[girl saveInBackground];
PFRelation *relation = [item relationForKey:@"owners"];
[relation addObject:girl];
[item saveInBackground];
So I want this item to be owned by several girls however when I run the program I get this error:
Error: can't add a non-pointer to a relation (Code: 111, Version: 1.6.0)
Can someone help please?
Thank you
You need to save your objects
girl1
andgirl2
before saving the relationship. Otherwise, even thought your local copy knows about them, the server does not.UPDATE
You also need to make sure the saves for
girl1
andgirl2
anditem
complete before you save the relation. However, you probably don't want to run these saves on the primary thread, so I'd recommend something like this (which I just ran without issue):