query.get(playerID, {
success: function(player) {
var numOfCoins = activeTeam.get("numOfCoins");
var playerPrice = player.get("price");
// Check if they have enough coins
if(numOfCoins >= playerPrice)
{
// Add to buy player array
var NewTeam = Parse.Object.extend("NewTeam");
var passiveTeam = new NewTeam();
passiveTeam.id = player.get("team").id;
// Remove from passive team (seller) array
passiveTeam.remove("players", player);
// Set player's team to the buyer's team (active team)
player.set("team", activeTeam);
// Add to the active team (buyer) array
activeTeam.add("players", player);
// ------ Save the player and both teams ------
Parse.Object.saveAll([activeTeam, passiveTeam, player], {
success: function(list)
{
response.success(list[2]); // also tried response.success(player);
},
error: function(error)
{
response.error(error);
}
});
I've posted a block of code (above) that queries a player (based on a ID requested from the client) gets the Player object and saves it. If the SaveAll is successful, I want to return the modified player back to the client.
However, I'm getting the following error "Failed with: Uncaught Tried to save an object with a pointer to a new, unsaved object.".
I've tried both using an index into the list to return the ParseObject in the response and using the variable name.
Do I need to query the player again after saving and return this in the response? Seems a bit overkill to need another API request to query the player I've just modified and saved.
Any help would be greatly appreciated. Thanks Alex.