I am currently working on retrieving the Game ID generated by the APIService.postData
method for the game. The goal is to utilize this Game ID within the Angular foreach loops to maintain foreign key constraints on the RESTful side.
Any advice on extracting the game ID from there?
P.S. I am already familiar with the scope issue.
this.createGame = function() {
APIService.postData('game', '', $scope.newGameData).then(function (data) {
$scope.newGameID = data.id;
});
// Iterating through each added class and appending the game_id to the object to facilitate smooth DB insertion on the RESTful side.
angular.forEach($scope.newGameData.classes, function (key, value) {
$scope.newGameData.classes[value].game_id = $scope.newGameID;
APIService.postData('game-class', '', $scope.newGameData.classes[value]);
});
// Cycling through each added race and adding the game_id to the object to ensure seamless DB insertion on the RESTful side.
angular.forEach($scope.newGameData.races, function (key, value) {
$scope.newGameData.races[value].game_id = $scope.newGameID;
APIService.postData('game-race', '', $scope.newGameData.races[value]);
});
$scope.newGameData = {
name: ""
};
$scope.race_counter = 0;
$scope.class_counter = 0;
$scope.newGameData.classes = [{id: $scope.class_counter}];
$scope.newGameData.races = [{id: $scope.race_counter}];
$scope.successMessage = "New 'Game' has been added!";
$scope.action = 'showGames'; // Default action.
this.getGames();
$window.scrollTo(0, 0);
};