Reputation: 33
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.
Upvotes: 1
Views: 95
Reputation: 2717
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);
Upvotes: 0