使用objectid解析ios wherekey [英] Parse ios wherekey using objectid

查看:53
本文介绍了使用objectid解析ios wherekey的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Parse的"Message"表中,有一个称为对话"的字段,它是pointerConversation(数据库中的另一个表)的字段.

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

要查询Message,我可以这样做:

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) {

          ...

    }];

还是我必须获取实际的PFObject * myConversation并使用它...

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) {

          ...

    }];

似乎#1不起作用,但是#2起作用...我的问题是我怎样才能使#1起作用(即,当我有一个指针字段时,使用PFObject的ID进行查询)

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只是一个字符串,如果您的对话"键包含指向myConversation的指针,则必须在等号中包含PFObject.

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

如果只有objectId,则可以使用以下命令搜索没有数据的指针:

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) {

      ...

}];

这篇关于使用objectid解析ios wherekey的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆