我在我的应用程序中使用 Parse.com,我创建了一个“帖子”类,在里面我有一个指针,它指定哪个用户发送了帖子。现在我在帖子的时间线上看到了创建帖子的用户名的时间。由于用户是指针,我无法正确查询,您知道我该如何解决这个问题吗?
最佳答案
诀窍是使用 PFQuery includeKey
让 Parse 自动填充相关的指针数据。
user
数据将被下载,无需您再次查询。
PFQuery *query = [PFQuery queryWithClassName:@"Post"];
// Include the user data with each post
[query includeKey:@"title_of_userpointer_column"];
[query findObjectsInBackgroundWithBlock:^(NSArray *postObjects, NSError *error)
{
if (!error) {
NSLog(@"Successfully retrieved: %d items", [postObjects count]);
// postObjects now contains the latest 100 Posts, and the "title_of_userpointer_column" field
// has been populated.
// For example:
for (PFObject * postObject in postObjects) {
// This does not require a network access.
PFObject *postAuthor = [postObject objectForKey:@"title_of_userpointer_column"];
NSLog(@"retrieved related Post Author: %@", postAuthor);
}
}
关于parse-platform - 在 Parse.com 中使用指针用户查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19099137/