2014-11-05 70 views
1

我试图让对象(MainObject)不包含在内部查询中,但它不起作用。 它返回对象,就好像没有定义内部查询一样。解析子查询whereKey:doesNotMatchKey:inQuery:其中innerquery返回对象,而不是字符串

我想这是因为我的innerquery返回对象和whereKey:doesNotMatchKey:inQuery:它正在等待一个字符串与objectId进行比较。

PFQuery *queryInner = [PFQuery queryWithClassName:@"InnerObject"]; 
[queryInner whereKey:@"status" equalTo:[NSNumber numberWithInt:0]]; 
[queryInner selectKeys:@[@"principalObject"]]; 

PFQuery *queryPrincipal = [PFQuery queryWithClassName:@"MainObject"]; 
[queryPrincipal whereKey:@"owner" equalTo:[PFUser currentUser]]; 
[queryPrincipal whereKey:@"objectId" doesNotMatchKey:@"principalObject" inQuery:queryInner]; 

[queryPrincipal findObjectsInBackgroundWithBlock:^(NSArray *returnedData, NSError *error) { 
... 
... 

是否有可能提取innerQuery中的对象的对象id没有2个请求? 是否可以将一个字符串(objectId)与另一列(principalObject)中的对象进行比较?

谢谢。

回答

0

随着韦斯在解析谷歌网上论坛建议:https://groups.google.com/d/msgid/parse-developers/46b5b8a9-dbb8-464d-8f54-db884e95d49e%40googlegroups.com

我对这个问题的解决方案是一个额外的键添加到只包含OBJECTID我“InnerObject”表。所以你会有指针列(principalObject)和ID(principalObjectId)。使用ID作为字符串查询的工作原理,但是我们在InnerObject中有一个新的不必要的列,浪费了一些空间并重载了一些对象的创建

为了简单起见,只需将它添加到“InnerObject”的beforeSave中云代码。它承认指向的对象不只是字符串键:例如...

Parse.Cloud.beforeSave("InnerObject", function(request, response) { 
    var myInnerObject = request.object; 
    if (myInnerObject.get("principalObject") != null && myInnerObject.get("principalObject").id != myInnerObject.get("principalObjectId")) { //Make sure it is set and it is not done 
    myInnerObject.set("pricipalObjectId", myInnerObject.get("principalObject").id); //The pointer won't have other data but it does have the ID 
    } 
    response.success(); 
}); 

请将只是有一个查询约束whereDoesNotMatchQuery是非常好的。

相关问题