2

I am following the tutorials on Parse.com but I don't seem to get it working properly. Here is my issue.

I have a class called Questions and a class named _User of type PFUser (it has a picture icon next to the class name). User logins via FB and is registered as a _User. I can see myself in the _User class.

I make a question and I have a field in the Question class named qOwner, which is the owner of the Question. This is being set when saving a new question via the ios app like this :

QuestionCard[@"qOwner"] = [PFUser currentUser];

I can see the objectId of myself in _User to be the value inside the qOwner column, at the row for the current question made.

_User class

Questions class

Problem is that I cannot retrieve the values inside my app. If I place in the correct place the below:

PFQuery *query = [PFQuery queryWithClassName:@"Questions"];
[query addAscendingOrder:@"createdAt"];

[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (!error) {
        // The find succeeded.
        NSLog(@"@@@ : Successfully retrieved %lu questions ", (unsigned long)objects.count);
        // Do something with the found objects
        NSLog(@"%@",objects);

        // fetched data are PFObjects
        // we need to convert that into a YesOrNo object
        // and then add it to _cards array

        for (PFObject *object in objects) {
            NSLog(@"currentUser : %@",[PFUser currentUser]);
            PFUser *qOwnerUser = [object objectForKey:@"qOwner"];
            NSLog(@"Question Made by : %@",qOwnerUser);
        }
.....

The following is being printed:

1)

@@@ : Successfully retrieved 1 cards 

2)

(
        "<Questions: 0x17011f5c0, objectId: zZWGsfciEU, localId: (null)> {\n    CardId = 999;\n     qOwner = \"<PFUser: 0x17037e000, objectId: LtdxP5K0n6>\";\n    type = 0;\n  }"

)

3)

currentUser : <PFUser: 0x174375e40, objectId: LtdxP5K0n6, localId: (null)> {
    facebookId = 10153480462518901;
    thumbnail = "<PFFile: 0x174479a80>";
    username = UYRRmfbXDHqr1Ws4VwJcAy2wx;
}

4)

Question Made by : <PFUser: 0x17037e000, objectId: LtdxP5K0n6, localId: (null)> {
}

1-2-3 seem correct, I can see the pointer relation. But why in 4 inside {} I see nothing? I would have expected to see the same user details as in 3.

Am I missing something?

kRiZ
  • 2,320
  • 4
  • 28
  • 39
ghostrider
  • 5,131
  • 14
  • 72
  • 120

1 Answers1

4

Parse does not fetch the pointer values by default in a query. You have to tell the query to include the pointer data using includeKey:. Do this:

PFQuery *query = [PFQuery queryWithClassName:@"Questions"];
[query addAscendingOrder:@"createdAt"];
[query includeKey:@"qOwner"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    ...
}];
kRiZ
  • 2,320
  • 4
  • 28
  • 39
  • 3
    Hmm I haven't noticed that in the documentation.. Thanks, i will try it once online and will accept the answer if correct! – ghostrider Jul 10 '15 at 14:34