0
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.

  • What about save activeTeam and passiveTeam first, then set player and save player? You don't need to query player again. – eth3lbert Jan 28 '15 at 15:50
  • I can try it but I thought that's what saveAll was suppose to be for (to batch save calls). It's really weird that if I remove the object from the response.success and say replace it with a string it works fine. It just doesn't like that object. – user3782934 Jan 28 '15 at 17:52

0 Answers0