Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Self-Destructing Message iPhone App Relating Users in Parse.com Adding Friends by Tapping on a Table View Cell

Finn Terdal
Finn Terdal
15,997 Points

Parse.com has changed their syntax for relational data!

I'm working through the video on adding PFRelations between PFObjects, and I'm pretty sure thus video is out of date. I followed the instructions in the video, but, when I looked at the Parse.com dashboard, nothing seems to have been done on the back-end--no new relations!

I did some digging, and discovered that the Parse Documentation for Relational Data doesn't match what was covered in the video. I'm pretty sure it's easy to fix, but I thought I should let people know, and I was wondering if anyone else has encountered this problem.

// Cheers! // Finn

2 Answers

Stone Preston
Stone Preston
42,016 Points

its almost exactly the same. instead of relationforKey you use relationForKey.

go to the relational data section under objects of the documentation here. scroll down until you see the part that mentions relations. it states:

You can also model a many-to-many relation using the PFRelation object. This works similar to an NSArray of PFObjects, except that you don't need to download all the Objects in a relation at once. This allows PFRelation to scale to many more objects than the NSArray of PFObject approach. For example, a User may have many Posts that they might like. In this case, you can store the set of Posts that a User likes using relationForKey:. In order to add a post to the list, the code would look something like

PFUser *user = [PFUser currentUser];
PFRelation *relation = [user relationForKey:@"likes"];
[relation addObject:post];
[user saveInBackground];

the code ben uses in the video to add an object to the relation is:

PFRelation *friendsRelation = [self.currentUser relationforKey@"friendsRelation"];
PFUser *user = [self.allUsers objectAtIndex:indexPath.row];
[friendsRelation addObject:user];

and then saves the user in the background. the only difference is the lower case f in relationforKey, this is has been deprecated and now the method is relationForKey

Finn Terdal
Finn Terdal
15,997 Points

Thanks, Stone! It turns out I had a different problem in my code that was causing the problem. The syntax has changed very slightly, but Xcode's autocomplete is an easy fix.