2015-09-04 49 views
0

我一直在查詢好友請求數據庫,但它返回整個表。約束是2個解析用戶和一個int。有沒有一個已知的錯誤,或者在我的代碼中有錯誤?我在android上做了同樣的查詢,它工作正常。複合查詢返回整個數據庫

  PFUser * unwanted = [self.allFriends objectAtIndex:2]; 
    self.currentUser = [PFUser currentUser]; 



NSLog(@"unwanted %@",unwanted); 

PFQuery *query1 = [PFQuery queryWithClassName:@"friendrequest"]; 
[query1 whereKey:@"user1" equalTo:self.currentUser]; 
[query1 whereKey:@"user2" equalTo:unwanted]; 
[query1 whereKey:@"status" equalTo:@3]; 
PFQuery *query2 = [PFQuery queryWithClassName:@"friendrequest"]; 
[query1 whereKey:@"user1" equalTo:unwanted]; 
[query1 whereKey:@"user2" equalTo:self.currentUser]; 
[query1 whereKey:@"status" equalTo:@3]; 
PFQuery *query3 = [PFQuery queryWithClassName:@"friendrequest"]; 
[query1 whereKey:@"user1" equalTo:self.currentUser]; 
[query1 whereKey:@"user2" equalTo:unwanted]; 
[query1 whereKey:@"status" equalTo:@1]; 
PFQuery *query4 = [PFQuery queryWithClassName:@"friendrequest"]; 
[query1 whereKey:@"user1" equalTo:unwanted]; 
[query1 whereKey:@"user2" equalTo:self.currentUser]; 
[query1 whereKey:@"status" equalTo:@1]; 
PFQuery *finalQuery = [PFQuery orQueryWithSubqueries:@[query1,query2,query3,query4]]; 
[finalQuery findObjectsInBackgroundWithBlock:^(NSArray *objects,NSError *error){ 
    if(!error){ 
     NSLog(@"gotem %lu",(unsigned long)objects.count); 
    } 

}]; 

回答

1

不良的複製/粘貼!退出這樣做。如果您手動輸入這些內容,則應輸入正確的查詢號碼,而不是不斷更改query1的設置。就像你現在所做的那樣,你有三個對friendRequest類沒有任何限制的查詢,並返回每個實例。

+0

哈哈哈感謝有時你只需要另一套眼睛,或者只是更好的編碼技能。 – waffles

+0

儘快找到良好編程習慣的習慣,男人。我正在努力爲生產應用上的懶惰編程而努力...... –