I'm trying to grasp the pattern here. If I have "journals" that belong to users (PFUsers), how can I query for all the journals that belong to that user? I don't think this is right, but one way to do it would be to set the username on all journal objects since I know it will be unique, then query all journals with that username. Is that the best way? Seems like there should be a cleaner way of handling relationships.
1 Answer
Found the answer to my question in the iOS guide. My searches for "nested" didn't find it. "Associations" did :).
PFUser *user = [PFUser currentUser];
// Make a new post
PFObject *post = [PFObject objectWithClassName:@"Post"];
[post setObject:@"My New Post" forKey:@"title"];
[post setObject:@"This is some great content." forKey:@"body"];
[post setObject:user forKey:@"user"];
[post save];
// Find all posts by the current user
PFQuery *query = [PFQuery queryWithClassName:@"Post"];
[query whereKey:@"user" equalTo:user];
NSArray *usersPosts = [query findObjects];
1 Comment
Timothy Walters
Also for when you need many-to-many joins, you can add a new column of type "Relation", in many ways it works like an array, but you can query it (in fact that's the only way to get information out of it, you can't use
includeKey:)