2

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 1

1

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];
Sign up to request clarification or add additional context in comments.

1 Comment

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:)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.