2016-01-23 55 views
0

我在我的應用程序的結構如下:Parse.com:在化合物query.or()包括嵌套指針

Messages -> receiver-> User (User.username) 
      sender -> User (User.username) 

其中 - >表示的指針。我想要將當前用戶發送給的所有消息發送給他們預期的Receiver。並且由 當前用戶接收以創建對話摘要。

問題是,接收方用戶名始終是空的在查詢上,而發送者用戶名是罰款。 如何獲取接收器的用戶名?

var Receiver = new Parse.User(); 
Receiver.id = 'XXXXXX'; // the problem seems to be here, why??? 
// Query messages sent by current user 
var senderQuery = new Parse.Query(MyParseMessage); 
senderQuery.equalTo("receiver", Receiver); 
senderQuery.equalTo("sender", Parse.User.current()); 

// Query messages sent by other user 
var receiverQuery = new Parse.Query(MyParseMessage); 
receiverQuery.equalTo("receiver", Parse.User.current()); 
receiverQuery.equalTo("sender", Receiver); 

// Combined Query with OR condition 
var messageQuery = Parse.Query.or(senderQuery, receiverQuery); 
// this should include the receiver data 
receiverQuery.include('receiver'); // this is not working, why is not working? 

messageQuery.find(); 

我在想什麼?謝謝!

+0

JavaScript沒有[指針](HTTPS: //en.wikipedia.org/wiki/Pointer_%28programming%29)。你真的在使用哪種語言?或者,你能否改寫爲不要在編程中使用具有明確定義的詞語,但是你使用的意思是別的嗎? –

+0

這是Parse.com中的一個指針,謝謝你的回答。 – lito

回答

0

爲了解決這個問題我做了一件奇怪:我不得不去解析,然後找到用戶對象,然後做出我想要的查詢:

var deferral = $q.defer(); 
var query = new Parse.Query(Parse.User); 
query.equalTo("objectId", receiverId); 
query.find().then(function (user) { 
// Query messages sent by current user 
    var senderQuery = new Parse.Query(MyParseMessage); 
    senderQuery.equalTo("receiver", user[0]); 
    senderQuery.equalTo("sender", Parse.User.current()); 

// Query messages sent by other user 
    var receiverQuery = new Parse.Query(MyParseMessage); 
    receiverQuery.equalTo("receiver", Parse.User.current()); 
    receiverQuery.equalTo("sender", user[0]); 

// Combined Query with OR condition 
    var messageQuery = Parse.Query.or(senderQuery, receiverQuery); 
// this should include the receiver data 
    receiverQuery.include('receiver'); 

    return deferral.resolve(messageQuery.find()); 
}); 
return deferral.promise;