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

Get all objects from one Parse class that are not mentioned in another class

我正在尝试查询 confessions class 中的所有记录,其 author 不是 [PFUser currentUser]... 但只有我们的 [PFUser currentUser]未在 ratings class.

评分

confessions class:

ratingsclass:

基本上,我想将这两个查询合二为一(以某种方式):

// 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 :)

如果没有简单的方法来实现我想要的,你认为我应该改变模型吗?如何改变?我是否应该只获取所有评级,然后以某种方式忽略所有等于 ratings.confessionqConfessions?欢迎任何帮助。谢谢。

试试这个:

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

我通过在 Parse 上向 ratings class 添加一个 confessionId 字段并使用以下代码来解决此问题:

// 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
    }
}];