0

Ok so let's say I have a post of an event, and users can click a button to notify that they are attending this event. As of now I have a class called Activity in which I save the current user and the event to this class, so theres 2 columns. If I want to query all users who are attending an event, am I headed in the right direction to do this, or am I doing it complentely wrong?

So far I have:

-(PFQuery*)queryForTable {

PFQuery *activityQuery = [PFQuery queryWithClassName:@"Activity"];

[activityQuery whereKey:@"event" equalTo:self.event];
[activityQuery includeKey:@"going"];

return activityQuery;
}

cellForRowAtIndex:

 UILabel *title = (UILabel*) [cell viewWithTag:1];
 title.text = [object objectForKey:@"going.username"];
0

2 Answers 2

1

You can actually see what you have been done in the Parse dashboard. That's also their purpose to develop a data browser like this. It's way more convenient.

For your case, you just need to check whether the type is Pointer. Try to click on that if so in the dashboard. It will direct you to the target object.

Would suggest you to read this article first, it's about the relation: https://parse.com/docs/relations_guide Then, you should go check the iOS SDK tutorial: includeKey is definitely what you need to use.

Here is the sample from Parse:

PFQuery *query = [PFQuery queryWithClassName:@"Comment"];

// Retrieve the most recent ones
[query orderByDescending:@"createdAt"];

// Only retrieve the last ten
query.limit = 10;

// Include the post data with each comment
[query includeKey:@"post"];


[query findObjectsInBackgroundWithBlock:^(NSArray *comments, NSError *error) {
    // Comments now contains the last ten comments, and the "post" field
    // has been populated. For example:
    for (PFObject *comment in comments) {
         // This does not require a network access.
         PFObject *post = comment[@"post"];
         NSLog(@"retrieved related post: %@", post);
    }
}];
Sign up to request clarification or add additional context in comments.

5 Comments

That's not what I was asking for, but thanks for the answer Lucas
If you play around the data browser, that's also pretty you can do in code. I t means that YES. You can do it by creating object that way.
I've updated my question to show my query, my next question is can I use dot notation to retrieve the users information?
Answer is no. You can only get a property using that syntax. Parse has a full documentation to teach you how to fetch the data using Pointer, Relation. Go with that.
So I can just use the includeKey, without dot notation, and define what properties I need in the cell?
1

Your code looks right on so far. Then to retrieve your Activity class values, you can use:

PFQuery *activityQuery = [PFQuery queryWithClassName:@"Activity"];
// Set contraints here, example:
[activityQuery setLimit:100];

[query findObjectsInBackgroundWithBlock:^(NSArray *array, NSError *error) {
if (!error) {
// Success, do something with your objects.
}
}];

2 Comments

Ok so how do I set it up to where I can retrieve the profile image and username for the user who is attending. Im confused about using the includeKey and how far I can reach into the relation. –
Look into PFQuery. You can set up a query to get data from users.

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.