Ios wherekey parameter using objectid

In my MessagePars table , I have a conversation field that appears pointeron Conversation(another table in my database).

To fulfill the request for Message, can I do:

    PFQuery *messageQuery = [PFQuery queryWithClassName:@"Message"];
    [messageQuery whereKey:@"conversation" equalTo:_conversation.objectid];
    [messageQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {

          ...

    }];

or do I need to get a real PFObject * myConversation and use it ...

    PFQuery *messageQuery = [PFQuery queryWithClassName:@"Message"];
    [messageQuery whereKey:@"conversation" equalTo:myConversation];
    [messageQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {

          ...

    }];

It seems that # 1 does not work, but # 2 does ... my question is how can I make # 1 work (i.e. use the PFObject id to query when I have a pointer field)

+4
source share
1 answer

.objectId - , "" myConversation, PFObject , .

objectId, , :

PFObject * myConversation = [PFObject objectWithoutDataWithClassName:@"Conversation" objectId:_conversation.objectid];

// continue here

[messageQuery whereKey:@"conversation" equalTo:myConversation];
[messageQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {

      ...

}];
+5

Source: https://habr.com/ru/post/1530718/


All Articles