指针字段toUser需要指针值Parse.com

时间:2015-05-19 17:21:57

标签: ios objective-c uitableview parse-platform

我有一个名为Messages的Parse.com类,其中我有3列:

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

在我的UITableView中,我尝试检索Messages-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);
        }
    }];
}

1 个答案:

答案 0 :(得分:3)

将objectIds与指针混淆是一个常见的错误。将equalTo:test更改为:

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

修改 在JS / Cloud代码中,它的工作方式相同:

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