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)
.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) {
...
}];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With