0

I am writing a script on parse.com's javascript cloud code SDK. I am having trouble with the "doesNotMatchQuery" method. I have a "class" called activity, this contains a field called movie and a field called fromUser containing the user object of that activity,

Activity Class

i have a class called movie. I want to get all movies that do not have activity from this user.

Movie Class

The code I am using(which i know is wrong and doesNotMatchQuery is not the correct method).

  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.

1 Answer 1

1

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.

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);
});
});
Sign up to request clarification or add additional context in comments.

3 Comments

I tried that, but it doesn't work. I guess its because it would be the movie.objectId I also tried that query.doesNotMatchKeyInQuery("objectId", "movie.objectId", queryUserActivity);
I thought so. I updated my answer with a possible solution to the problem
Thanks Mo Nazemi, that solution works after a couple of edits(syntax errors).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.