parse.com:如何将指针键与对象进行比较? [英] parse.com: How to compare pointer-keys with objects?

查看:62
本文介绍了parse.com:如何将指针键与对象进行比较?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为iOS应用程序使用后端服务parse.com,但在正确查询它时遇到了问题.我需要方法whereKey:matchesKey:inQuery;

I am using the backend service parse.com for a iOS app and I have a problem with querying it properly. I need help with the method whereKey:matchesKey:inQuery;

我有此代码:

//NOT WORKING
PFQuery *query1 = [PFQuery queryWithClassName:@"Object"];

PFQuery *query2 = [PFQuery queryWithClassName:@"ObjectsRelations"];
[query2 whereKey:@"user" equalTo:[PFUser currentUser]];

[query1 whereKey:@"objectId" matchesKey:@"objectPointer" inQuery:query2];
[query1 findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    // No objects
}];

它没有按照我想要的方式工作.我尝试了几种方法来将类"ObjectsRelations"中的键"objectPointer"(指向类Object的实例的指针)与查询1中的实际对象进行比较.我没有返回任何对象,因为比较不能按我想要的方式工作,因为键objectId只是一个字符串,而键objectPointer是指向对象的指针.

It is not working the way I want. I have tried several ways for it to compare the key "objectPointer" in class "ObjectsRelations" (which is a pointer to an instance of class Object) to the actual Object in query 1. I do not get any objects back, because the comparison does not work as I want, since the key objectId is just a string and the key objectPointer is a pointer to a Object.

运行此代码时,我得到了预期的结果,但这需要我执行两个api请求才能将实际的objectId作为字符串获取!

When I run this code, I get the intended result, but this requires me to do two api-requests to get the actual objectId as a string!

//WORKING
PFQuery *query = [PFQuery queryWithClassName:@"Object"];

PFQuery *query2 = [PFQuery queryWithClassName:@"ObjectRelations"];
[query2 whereKey:@"user" equalTo:[PFUser currentUser]];

[query2 findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    PFObject *firstObject = [((PFObject*)[objects firstObject]) objectForKey:@"objectPointer"];

[query whereKey:@"objectId" equalTo:firstObject.objectId];

[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    //Getting the objects correctly from the class Object!
}];
}];

如何使用单个api请求执行此操作?如何通过查询将类的实例与类的指针进行比较?

How to do this with a single api-request? How to compare a instance of a Class to a pointer of a class with a query?

我想要做的是这样的事情:(伪代码)

Something like this is what i want to do: (Pseudo Code)

[query1 where:SELF matches:@"objectPointer" inQuery:query2];

有什么建议吗?

推荐答案

我刚刚搜索了这个完全相同的问题,并且在Parse论坛上有很多与此有关的问题:

I just searched this exact same problem and there are a number of questions on the Parse forum regarding it:

使用object_id进行嵌套查询时遇到的问题
协助进行关系查询
比较指向查询中的指针的字符串与不匹配查询中的键

Trouble with nested query using object_id
Assistance with relational query
Compare string to pointer in query with does not match key in query

第一个解释了一个黑客,该黑客在您的ObjectRelations类中包含一个额外的字段(在这种情况下).该键/字段将是一个字符串,该字符串将成为指针的objectId.它将是保存指针的键/字段的补充.

The first one explains a hack to include an extra field (in this case) in your ObjectRelations class. This key/field would be a string that would be the objectId of the pointer. It would be in addition to the key/field that holds the pointer.

如果您浏览这些问题,您会发现到目前为止,似乎没有直接从Parse那里得到答案.

If you look through the questions you can see that as of now there doesn't seem to be an answer directly from Parse regarding this.

这篇关于parse.com:如何将指针键与对象进行比较?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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