我有两个解析表POST和COMMENT。 我想获得所有帖子,有新的评论。我正在根据post table中的viewingDate字段和Comment Table中的createdAt字段进行检查。JOIN TABLES parse.com
SELECT *
FROM POST p
INNER JOIN COMMENT c
ON p.objectId==c.pId and c.createdAt > p.viewedDate;
PFQuery *post = [ParsePost query];
[post findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
PFQuery *post = [ParsePost query];
PFQuery *comment = [ParseComment query];
//how add greater than for keys from other table?
//line below crashes
[comment whereKey:@"createdAt" greaterThan:[objects valueForKey:@"viewedDate"]];
[comment whereKey:@"post" matchesKey:@"objectId" inQuery:post];
[post whereKey:@"objectId" matchesKey:@"post" inQuery:comment];
[post findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
}];
}];
UPDATE * 这是我要做的事目前 *
PFQuery *postView = [ParsePost query];
[postView whereKey:@"author" equalTo:[ParseLigoUser currentUser]];
[postView findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
for (ParsePost *post in objects) {
PFQuery *comment = [ParseComment query];
[comment orderByDescending:@"createdAt"];
if (post.viewedDate) {
[comment whereKey:@"createdAt" greaterThan:post.viewedDate];
}else {
continue;
}
[comment whereKey:@"post" equalTo:post];
[comment countObjectsInBackgroundWithBlock:^(int number, NSError *error) {
if (number>0) {
if (!self.newposts) {
self.newposts = [NSMutableDictionary dictionary];
}
[self.newposts setObject:@"NOTSEEN" forKey:[post.objectId stringByAppendingString:@"Comment"]];
self.postCount += 1;
}
}];
}
}];
更新2与关系
PFQuery *postView = [ParsePost query];
[postView whereKey:@"author" equalTo:[ParseLigoUser currentUser]];
[postView setLimit:100];
[postView findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
for (ParsePost *post in objects) {
PFRelation *rel = [post relationForKey:@"hasComment"];
PFQuery *query = [rel query];
[query orderByDescending:@"createdAt"];
if (post.viewedDate) {
[query whereKey:@"createdAt" greaterThan:post.viewedDate];
}else {
continue;
}
[[rel query] countObjectsInBackgroundWithBlock:^(int number, NSError *error) {
if (number>0) {
if (!self.newposts) {
self.newposts = [NSMutableDictionary dictionary];
}
[self.newposts setObject:@"NOTSEEN" forKey:[post.objectId stringByAppendingString:@"Comment"]];
self.postCount += 1;
}
}];
}
}];
什么是p.viewedDate?上次该帖子是由任何用户查看的?你能解释这个领域背后的推理吗? – Moonwalkr
是的,上次帖子的作者查看后。 –