我正在查询 parse 上的关系数据,我希望对象按创建日期排序。我以前使用过这种方法,但无法使用关系数据获得有序查询。查询返回是随机顺序的。提前致谢!这是我的代码:
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;
}