Harshit Gupta
Harshit Gupta

Reputation: 271

How to retrieve value from second level pointer in Parse for iOS using Objective-C

I have following structure in Parse

Class_A

  1. objectID
  2. b_ID (this is a pointer having value as objectID to B)

Class_B

  1. objectID
  2. c_ID (this is a pointer having value as objectID to C)
  3. someParameterinB

Class_C

  1. objectID
  2. someParameterinC

I am using following code to retrieve;

PFQuery *query = [PFQuery queryWithClassName:@"Class_A"];
    [query includeKey:@"b_ID"];
    [query includeKey:@"Class_B.c_ID"];

    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error) {
            // The find succeeded. The first 50 objects are available in object
            self.myArray = [[NSArray alloc] initWithArray:objects];
        } else {
            // Log details of the failure
            NSLog(@"Error: %@ %@", error, [error userInfo]);
        }
    }];

Now when it comes to display in UITableViewCell, I am using following code:

PFObject *aObject = [self.myArray objectAtIndex:indexPath.row];

PFObject *bObject = [aObject objectForKey:@"b_ID"];

PFObject *cObject = [bObject objectForKey:@"c_ID"];

I am getting issue with cObject. Can you please help?

Upvotes: 3

Views: 542

Answers (1)

Wain
Wain

Reputation: 119041

Replace these lines:

[query includeKey:@"b_ID"];
[query includeKey:@"Class_B.c_ID"];

with

[query includeKey:@"b_ID.c_ID"];

and the query response will include both B and C objects.

Upvotes: 2

Related Questions