我在Parse上有一个云功能。当它被调用时,它会检索PFObject
,然后在该对象和用户之间添加关系。这部分工作正常(见功能结束)。
我无法获取选择PFObject
的查询以忽略用户已与之相关的查询
这是我的代码:
Parse.Cloud.define("NextMedia", function (request, response) {
var LikeRequest = Parse.Object.extend("LikeRequest");
var query = new Parse.Query(LikeRequest);
query.equalTo("completed", false);
console.log("user: " + Parse.User.current().id);
query.notEqualTo("user", Parse.User.current());
// Also only fetch if never been sent before
// HERE SHOULD USE THE BELOW RELATIONSHIP
var innerQuery = new Parse.Query(Parse.User);
innerQuery.exists(Parse.User);
query.matchesQuery("sentTo", innerQuery);
query.ascending("createdAt");
query.first({
success: function (object) {
// Successfully retrieved the object.
console.log("Got 1 object: " + object.get('mediaId'));
// Record that the user has been sent it
var user = Parse.User.current();
var relation = object.relation("sentTo"); // RELATION ADDED HERE
relation.add(user);
object.save();
response.success(object);
},
error: function (error) {
console.log("Error: " + error.code + " " + error.message);
response.error("Error getting next mediaId");
}
});
});
我确定我只是不了解关系查询语法的工作原理。
答案 0 :(得分:2)
这段话:
// Also only fetch if never been sent before
// HERE SHOULD USE THE BELOW RELATIONSHIP
var innerQuery = new Parse.Query(Parse.User);
innerQuery.exists(Parse.User);
query.matchesQuery("sentTo", innerQuery);
可以更改为:
// Also only fetch if never been sent before
query.notContainedIn("sentTo",[Parse.User.current()])
有效。Parse Query
答案 1 :(得分:1)
如果要检索与多个值不匹配的对象,可以使用notContainedIn
// Finds objects from anyone who is neither Jonathan, Dario, nor Shawn
query.notContainedIn("playerName",
["Jonathan Walsh", "Dario Wunsch", "Shawn Simon"]);
答案 2 :(得分:1)
我认为Kerem有部分正确但不包含在你的情况下不够动态。
您需要构建query from the relation,然后使用doesNotMatchKeyInQuery从外部查询中排除这些对象。