Pergunta

** Edit : sorry I had to edit my question to clean out the other users i had so i delete everything.

so i manage to make some kind of relation between two users in one table on parse, this is how it's look : enter image description here

my class is NewChat and the user 'XcnKqF0tmO' is my Current user. i'm trying to create an query to receive a text ( the text is : hello) from another class called phoneNumber : enter image description here

as you can see the receiver 'T9kDJwePc' (on the first picture) is the same user 'ZZ6mRK..' (on the second picture. what i'm trying to do is to create a query from the Sender 'XcnKqf0tmO' (1st picture) to the T9kPDJwePc who is actually ( if i click on the reciever name ) is ZZ6MRKr5J1 and get the text " hello " into my TextField. I tried the following combination which didn't work :

  PFQuery *newOne = [PFQuery queryWithClassName:@"NewChat"];
// [newOne includeKey:@"reciever"]; <--- i tried with this line and with it
[newOne whereKey:@"sender" equalTo:[PFUser currentUser]];

PFQuery *phoneNumber = [PFQuery queryWithClassName:@"phoneNumber"];
[phoneNumber whereKey:@"objectId" matchesKey:@"reciever" inQuery:newOne];
[phoneNumber findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {

    NSLog(@"  object %@", objects);

}];

my query return with no result , my NSLOG show : " object ( ) ". why I have no results ? since the receiver name on the first image and the object ID on the second image are equal...

Foi útil?

Solução

The problem is that the pointer nrlsl9lkvt on the first picture points NOT to the record with the testing123 text, but to the record below. The phoneNumber record with the testing123 text has objectId o5igPWMaat, not nrlsl9lkvt.

You can get the text by quering for the NewChat object and use

[query includeKey:@"receiver"]; 

to ensure the phoneNumber object is downloaded as well. Just add a text to the right object in phoneNumber, and you're all set

UPDATE

Since you edited your question:

Your query should return the object you want (with objectId T9kPD...). Did you try the log statement I suggested? NSLog(@"objects: %d", [objects count]);

To get the text you want:

PFObject *object = [objects lastObject];  // Since your query should return only 1 object
NSLog(object[@"text"]);  // The "text" property of the object returned

If you're only interested in one object (like above), or KNOW there will only be one object, you should probably use getFirstObjectInBackgroundWithBlock: instead of findObjectsInBackground.... This will return one object instead of an array, and remove the need to call [objects lastObject];

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top