1

I'm very new to Parse and am trying to get some logic working in my beforeSave trigger.

The History class is made up as: game, gameWinners, gameLosers

From android I'm passing an array of ParseUser Pointers for gameWinners and gameLosers.

In the log I see that the data arrives fine:

Input: {"original":null,"update":{"ACL":{"*":{"read":true,"write":true},"k2UVtUJjDd":{"read":true,"write":true}},"game":{"__type":"Pointer","className":"Games","objectId":"mTopB9RdmQ"},"gameLosers":[[{"__type":"Pointer","className":"_User","objectId":"WMpIFuNnBH"},{"__type":"Pointer","className":"_User","objectId":"PTvaGdsyjp"}]],"gameWinners":[[{"__type":"Pointer","className":"_User","objectId":"Re1llgmbwi"}]],"submitter":{"__type":"Pointer","className":"_User","objectId":"k2UVtUJjDd"}}}

But calling request.object.get("gameWinners") I get:

[{"objectId":"Re1llgmbwi"},{"objectId":"WMpIFuNnBH"}]

What happened to the Pointer type? I just now have objectId's and when using them in a containedIn query, I get the error

pointer field player needs a pointer value

beforeSave code snippet that fails with the containedIn statement:

Parse.Cloud.beforeSave("History", function(request, response) {
if(request.object.get("game") === null)
    response.error("Game name was not specified");
else {
    // Get Ratings of all gameWinners
    var gameWinnerRatingsQuery = new Parse.Query("Ratings");
    gameWinnerRatingsQuery.equalTo("game", request.object.get("game"));
    gameWinnerRatingsQuery.containedIn("player", request.object.get("gameWinners"));
    gameWinnerRatingsQuery.find({

I should mention that the Ratings Class is setup so that game is a Pointer and player is a Pointer as well. The single game Pointer passed from Android works fine, I'm just not understanding how to apply the list of Pointers.

Thanks for any help.

1 Answer 1

0

Using Underscore map function, build an array of User objects for all the winners:

 var winnersList = _.map(request.object.get("gameWinners"), function(winner) {
    var playerObject = new Parse.User();
    playerObject.id = winner.id;
    return playerObject;
}

Then use the player list in your constraint:

gameWinnerRatingsQuery.containedIn("player", winnersList);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I'll give that a shot when I get home tonight. I was trying something similar but was using '.objectId' instead of '.id' as that looked to be what the field was called.

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.