Parse.com:在复合查询中包含嵌套指针.or()

时间:2016-01-23 13:24:25

标签: javascript parse-platform

我的应用程序中有以下结构:

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();

我错过了什么?谢谢!

1 个答案:

答案 0 :(得分:0)

为了解决这个问题,我做了一些奇怪的事情:我必须去Parse然后找到User Object然后进行我想要的查询:

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;