[英]Get all objects from one Parse class that are not mentioned in another class
I'm trying to query all records from confessions
class whose author
is not [PFUser currentUser]
... but only those that our [PFUser currentUser]
didn't rate on in ratings
class. 我正在尝试从
confessions
类中查询所有记录,这些记录的author
不是[PFUser currentUser]
...而是仅那些我们的[PFUser currentUser]
在ratings
类中未对其ratings
。
confessions
class: confessions
班:
ratings
class: ratings
等级:
Basically, I want to connect these two queries into one (somehow): 基本上,我想将这两个查询连接为一个(以某种方式):
// 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 :)
If there is no easy way to achieve what I want, do you think I should change the model and how? 如果没有简单的方法来实现我想要的目标,您认为我应该改变模式吗?如何改变? Should I just fetch all the ratings and then somehow ignore all
qConfessions
that are equal to ratings.confession
? 如果我只是获取所有收视率,然后以某种方式忽略所有
qConfessions
是等于ratings.confession
? Any help would be welcome. 任何帮助都将受到欢迎。 Thank you.
谢谢。
Try this: 尝试这个:
// get all qConfessions that are not in qRatings.confession
[qRatings whereKey:@"confession" doesNotMatchQuery: qConfessions];
[qRatings findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (error == nil) {
} esle {
}
}];
I've made a workaround by adding a confessionId
field to ratings
class on Parse and using the following code: 我通过将
confessionId
字段添加到Parse上的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
}
}];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.