简体   繁体   English

解析Javascript云代码嵌套查询

[英]Parse Javascript Cloud Code Nested Query

I am writing a script on parse.com's javascript cloud code SDK. 我正在parse.com的javascript云代码SDK上编写脚本。 I am having trouble with the "doesNotMatchQuery" method. 我在使用“ doesNotMatchQuery”方法时遇到麻烦。 I have a "class" called activity, this contains a field called movie and a field called fromUser containing the user object of that activity, 我有一个称为“活动”的“类”,其中包含一个称为电影的字段和一个名为fromUser的字段,其中包含该活动的用户对象,

活动课

i have a class called movie. 我有一堂课叫做电影。 I want to get all movies that do not have activity from this user. 我想从该用户那里获取所有没有活动的电影。

电影课

The code I am using(which i know is wrong and doesNotMatchQuery is not the correct method). 我正在使用的代码(我知道这是错误的,dosNotMatchQuery不是正确的方法)。

  Parse.Cloud.define("recommendations", function(request, response) {
  var user = request.user;

  var queryUserActivity = new Parse.Query("Activity");
  queryUserActivity.equalTo("fromUser",user);

  var query = new Parse.Query("Movie");
  query.doesNotMatchQuery("movie", queryUserActivity);
  query.find({
    success: function(results) {
      response.success(results);
    },
    error: function() {
      response.error("movie lookup failed");
    }
  });
}

The problem is in the doesNotMatchQuery, only matches against a field, whereas i want it to match against the result objects from the "query", method "doesNotMatchKeyInQuery" comes close but still doesn't offer the ability to match the results of the query with a key. 问题是在dosNotMatchQuery中,仅与字段匹配,而我希望它与“查询”中的结果对象匹配,方法“ doesNotMatchKeyInQuery”接近但仍不提供匹配查询结果的功能用一把钥匙。

The code below finds the list of the movie objects that you do not want to return via Activity table and excludes them from you final Movie records. 下面的代码通过“ Activity表查找您不想返回的电影对象的列表,并将它们从最终的Movie记录中排除。

var _ = require('underscore');
Parse.Cloud.define("recommendations", function(request, response) {

var user = request.user;
var queryUserActivity = new Parse.Query("Activity");
queryUserActivity.equalTo("fromUser",user);
queryUserActivity.select("movie");

queryUserActivity.find().then(function(activities) {

    var movieObjIds = _.map(activities, function(activity) {
        return activity.get("movie").id; 
    });
    var query = new Parse.Query("Movie");
    query.notContainedIn("objectId", movieObjIds);
    return query.find();

}).then( function(results) {
      response.success(results);
}, function(error) {
      response.error(error);
});
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM