0
我在查詢關係數據的解析,我希望對象回來,他們被創建的日期排序。我以前使用過此方法,但一直無法使用關係數據獲得有序查詢。查詢返回的順序是隨機的。提前致謝!這裏是我的代碼:查詢關係分析關係數據不會回來排序使用orderedByAscending
PFQuery *postQuery = [PFQuery queryWithClassName:@"Post"];
[roomQuery whereKey:@"name" equalTo:self.postName];
NSError *error;
//done on main thread to have data for next query
NSArray *results = [postQuery findObjects:&error];
PFObject *post;
if ([results count]) {
post = [results objectAtIndex:0];
NSLog(@"results were found");
} else {
NSLog(@"results were not found");
}
PFRelation *commentsRelation = [@"Comments"];
[commentsRelation.query orderByAscending:@"createdAt"];
[commentsRelation.query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (error) {
NSLog(@"Error Fetching Comments: %@", error);
} else {
NSArray *comments = objects;
}
我沒有看到任何錯誤,只是閱讀代碼。你可以向我們展示一個評論中的數據樣本嗎? –
「PFRelation * commentsRelation = [@」評論「];」 這段代碼甚至不應該編譯,你能修復它以顯示如何獲得commentsRelation嗎? –