2014-02-27 32 views
2

我爲我的iPhone應用程序的後端使用Parse.com。在解析中獲取PFObject中的關係內容

我有一個名爲「Product」的類,它有一個名爲「Season」的列。當我查詢一組產品時,我也希望能夠輸出相關季節的數據。我把所有的產品進​​入一個PFobject所謂的「對象」

這工作得很好,從「產品」類獲取數據

NSLog(@"The PFObject is %@", object); 

這隻返回的關係的ID

NSLog(@"The season object is %@", [object objectForKey:@"Season"]); 

如何獲取相關季節的內容?

回答

0

假設類被稱爲「季節」,你可以通過它的id得到PFObject有以下幾點:

PFQuery *query = [PFQuery queryWithClassName:@"season"]; 
[query getObjectInBackgroundWithId:object[@"season"] block:^(PFObject *season, NSError *error) { 
    // Do something with the returned PFObject in the season variable. 
    NSLog(@"%@", season); 
}]; 

上查詢對象的詳細信息可以在iOS developer guide for Parse

0

中找到根據解析文檔,您可以獲取相關對象:

默認情況下,在獲取對象時,不會獲取相關的PFObjects。無法檢索這些對象的值,直到他們已經取像這樣:

PFObject *post = fetchedComment[@"parent"]; 
[post fetchIfNeededInBackgroundWithBlock:^(PFObject *object, NSError *error) { 
    NSString *title = post[@"title"]; 
}]; 

您在這裏可以找到關係的更多信息:https://parse.com/docs/ios_guide#objects-pointers/iOS