Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse ios wherekey using objectid

In my "Message" table in Parse I have a field called conversation, which is a pointer to a Conversation (another table in my database).

To query for a Message, can I do:

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

          ...

    }];

or do I have to get the actual PFObject *myConversation and use that...

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

          ...

    }];

It seems that #1 doesn't work, but #2 does...my question is how can I get #1 to work (i.e. use a PFObject's id to query when I have a pointer field)

like image 966
Apollo Avatar asked Mar 08 '14 04:03

Apollo


1 Answers

.objectId is just a string, if your "conversation" key contains a pointer to myConversation, then you must include a PFObject in the equal to.

If you only have the objectId, you can search pointers without data using:

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

// continue here

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

      ...

}];
like image 109
Logan Avatar answered Oct 17 '22 01:10

Logan