我的 Parse.com 应用程序中有以下多对多关系:
位 ↔ 消息
以下内容从“Bit”对象中获取相关消息:
const query = new Parse.Query('Bit');
query.include('participants');
query.include('user');
query.equalTo('objectId', req.query.bitId);
const promise = query.first().then(function(bit) {
return new Promise(function(resolve) {
const relation = bit.relation('messages');
relation.query().find().then(function(messages) {
resolve(messages);
});
});
});
*注意:messages 是关系列类型而不是指针类型。
messages
中的结果是一个数组,其中包含该位的所有相关消息。每条消息都包含一个指向名为sender
的用户的指针。是否可以在查询结果中包含此 User 对象?如果我可以像这样在关系查询上使用 include()
方法,那就太好了:
relation.include('sender');
最佳答案
您可以像限定任何其他查询一样限定关系的查询。 (另外,OP中有一些多余的 promise 代码。我稍微清理了一下,但答案的要点在注释行上)...
var query = new Parse.Query('Bit');
query.include('participants');
query.include('user');
query.equalTo('objectId', req.query.bitId);
var promise = query.first().then(function(bit) {
var relationalQuery = bit.relation('messages').query();
relationalQuery.include("sender"); // <-- the point
return relationalQuery().find();
}).then(function(messages) {
return resolve(messages);
});
关于javascript - Parse.com 是否允许在关系查询中包含指针?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34534069/