1

Below is my JS code that is supposed to delete a pointer reference to a 'Game' object which is stored in an array under the key 'games' in the 'team' object. Fetching works and all the 'success' logs below get called meaning that the .remove and .save functions get called, but for some reason, this does not do anything and the pointers still exist in the arrays after the execution of this code. What am I doing wrong?

var queryTeam = request.object.get("awayTeamID");

queryTeam.fetch({
    success: function(awayTeam){

        console.log("Success in Fetching awayTeam Object. Destroying Now.");

        awayTeam.remove(awayTeam.get("games"), request.object);
        awayTeam.save();

        var queryTeam = request.object.get("homeTeamID");

        queryTeam.fetch({
            success: function(homeTeam){

                console.log("Success in Fetching homeTeam Object. Destroying Now.");


                homeTeam.remove(homeTeam.get("games"), request.object);
                homeTeam.save();
            },
            error: function(homeTeam, error){
                console.error("Error removing game from homeTeam array! " + error.code + ": " + error.message);
            }
        });
    },
    error: function(myObject, error){
        console.error("Error removing game from awayTeam array! " + error.code + ": " + error.message);
    }

});

1 Answer 1

3

Your approach to removing is incorrect, you don't need to fetch the array to remove it, the remove request should be made on the object:

awayTeam.remove("games", request.object);
Sign up to request clarification or add additional context in comments.

Comments

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.