2015-05-19 69 views
3

我有一個Parse.com類調用消息,在那裏我有3列:指針字段

- fromUser - Pointer<_User> 
- toUser - Pointer<_User> 
- image - File 

在我的UITableView我試圖找回在消息中的所有對象-class其中toUser等於PFUser currentUser。當我做了查詢,我得到這個錯誤:

UserInfo=0x1702e3580 {code=102, temporary=0, error=pointer field toUser needs a pointer value, originalError=Error Domain=NSURLErrorDomain Code=-1011 "The operation couldn’t be completed. (NSURLErrorDomain error -1011.)"} { 
    code = 102; 
    error = "pointer field toUser needs a pointer value"; 
    originalError = "Error Domain=NSURLErrorDomain Code=-1011 \"The operation couldn\U2019t be completed. (NSURLErrorDomain error -1011.)\""; 
    temporary = 0; 
} 

這是我該怎麼辦查詢:

- (void)retriveMessages { 
    PFQuery *query = [PFQuery queryWithClassName:@"Messages"]; 
    [query whereKey:@"toUser" equalTo:[[PFUser currentUser] objectId]]; 
    [query orderByDescending:@"createdAt"]; 
    query.limit = 1000; 
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { 
     if (error) { 
      NSLog(@"Error: %@ %@", error, error.userInfo); 
     } else { 
      // Found messages! 
      self.messages = objects; 
      [self.tableView reloadData]; 
      NSLog(@"%@", objects); 
     } 
    }]; 
} 

回答

3

這是一個常見的錯誤是混淆的ObjectID與指針。更改equalTo:測試:

[query whereKey:@"toUser" equalTo:[PFUser currentUser]]; 

編輯 在JS /雲代碼,它的工作方式相同:

var someParseObject = // probably from another query 
query.equalTo("somePointerAttribute", someParseObject); 

// in cloud functions with a request parameter, the requesting user is available 
query.equalTo("pointerToAUserAttribute", request.user); 
+0

感謝的人!它工作完美:) – tracifycray

+1

如果我們不尋找一個用戶呢? –

+0

比較指針col時equalTo的第二個參數是PFObject。 PFUser是一個子類。 – danh