2014-09-28 3 views
0

내 응용 프로그램의 DB로 구문 분석을 사용하고 있습니다. 두 개의 객체 사이에 많은 관계가있는 앱을 만듭니다. 구문 분석 문서에서 가져온 내용관계의 상대방을 얻는 방법

// Create the post 
PFObject *myPost = [PFObject objectWithClassName:@"Post"]; 
myPost[@"title"] = @"I'm Hungry"; 
myPost[@"content"] = @"Where should we go for lunch?"; 

// Create the comment 
PFObject *myComment = [PFObject objectWithClassName:@"Comment"]; 
myComment[@"content"] = @"Let's do Sushirrito."; 

// Add a relation between the Post and Comment 
myComment[@"parent"] = myPost; 

// This will save both myPost and myComment 
[myComment saveInBackground]; 

관계를 저장 한 후 myPost 개체에서 myComment 개체를 가져 오는 방법은 무엇입니까? 감사합니다.

답변

1

양방향 관계가 아닙니다. myPost 객체에서 myComment 객체를 가져올 수 없습니다. MyComment 객체가 "부모"가 myPost로 설정된 주석에 대한 Comments 클래스를 쿼리하지 않게됩니다.

PFQuery *query = [PFQuery queryWithClassName:@"Comment"]; 
[query whereKey:@"parent" equalTo:myPost]; 
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { 
    ... 
}]; 
+0

감사합니다 ... 나는 왜 내 머리에 튀어 나오지 않았는 지 모르겠다. :) – YuviGr

관련 문제