2014-11-05 47 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是非常好的。

相關問題