从一个Parse类中获取另一个类中未提及的所有对象

时间:2015-06-07 13:46:10

标签: ios objective-c parse-platform pfquery

我正在尝试查询confessions不是author的{​​{1}}班级的所有记录...但只查看我们的[PFUser currentUser]没有评分的所有记录[PFUser currentUser]上课。

ratings上课:

enter image description here

confessions课程: enter image description here

基本上,我想将这两个查询连接成一个(不知何故):

ratings

如果没有简单的方法来达到我想要的目标,你认为我应该改变模型吗?我应该只是获取所有评分,然后以某种方式忽略所有等于// get all confessions from other users PFQuery *qConfessions = [PFQuery queryWithClassName:@"confessions"]; [qConfessions whereKey:@"author" notEqualTo:[PFUser currentUser]]; // get all ratings from this user PFQuery *qRatings = [PFQuery queryWithClassName:@"ratings"]; [qRatings whereKey:@"ratedBy" equalTo:[PFUser currentUser]]; // get all qConfessions that are not in qRatings.confession // YOUR HELP HERE :) 的{​​{1}}?欢迎任何帮助。谢谢。

2 个答案:

答案 0 :(得分:0)

试试这个:

// get all qConfessions that are not in qRatings.confession
[qRatings whereKey:@"confession" doesNotMatchQuery: qConfessions];
[qRatings findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (error == nil) {
    } esle {
    }
}];

答案 1 :(得分:0)

我已经通过在Parse上向confessionId类添加ratings字段并使用以下代码来解决方法:

// get all ratings from this user
PFQuery *qRatings = [PFQuery queryWithClassName:@"ratings"];
[qRatings whereKey:@"ratedBy" equalTo:[PFUser currentUser]];

// get all confessions from other users
PFQuery *qConfessions = [PFQuery queryWithClassName:@"confessions"];
[qConfessions whereKey:@"author" notEqualTo:[PFUser currentUser]];

// only fetch confessions that are not rated by current user
[qConfessions whereKey:@"objectId" doesNotMatchKey:@"confessionId" inQuery:qRatings];

// get all confessions from other users that are not rated by current user 
[qConfessions findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (!error) {
        // Success
    } else {
        // Error
    }
}];