You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
so in MyTeam I have result with team and players related to it.
now i want to edit some values in MyTeam entity and in players, and create new player, then save all this with try...catch handling error;
for exapmle:
MyTeam.title = "here are we go";
try {
await MyTeam.save();
} catch (error) {
console.log(error);
}
let newPlayer = new Player({...});
try {
await newPlayer.save();
} catch (error) {
console.log(error);
};
// here many other code ...
try {
MyTeam.Players.map(async player => {
player.years = player.years + 1;
await player.save();
});
} catch (error) {
console.log(error);
}
but there is a way if i need to save all my editing some like
let entityManager = new Sequeilize('entityManager');
MyTeam.title = "here are we go";
entityManager.add(MyTeam);
let newPlayer = new Player({...});
entityManager.add(newPlayer);
MyTeam.Players.map(player => {
player.years = player.years + 1;
entityManager.add(player);
});
try {
await entityManager.save();
} catch (error) {
console.log(error);
};
I an trying to do something like this, as described in #5471 (comment)
but model saving and updated as they push to array
let savingEntities = [];
MyTeam.title = "here are we go";
savingEntities.push(MyTeam);
let newPlayer = new Player({...});
savingEntities.push(newPlayer);
MyTeam.Players.map(player => {
player.years = player.years + 1;
savingEntities.push(player);
});
try {
await Promise.all(savingEntities);
} catch (error) {
console.log(error);
};
The text was updated successfully, but these errors were encountered:
Please use Github Issue Tracker only for reporting bugs, requesting new features or discussions. Ask questions on Stackoverflow sequelize.js tag or Slack. While I would like to help answer any questions but it still take too much time.
If you are reporting a bug please isolate it as SSCCE, present it nicely and follow issue template. This will help maintainers and contributors understand your issue quickly.
If you are requesting a feature spend some time to properly present your use case with some examples, current and expected outcome.
In my models I have One-To-Many relationships, and want to update and save all in one try..catch function to define if error there.
Team.hasMany(Player);
Player.belongsTo(Team);
result in json like this
so in MyTeam I have result with team and players related to it.
now i want to edit some values in MyTeam entity and in players, and create new player, then save all this with
try...catch
handling error;for exapmle:
but there is a way if i need to save all my editing some like
I an trying to do something like this, as described in #5471 (comment)
but model saving and updated as they push to array
The text was updated successfully, but these errors were encountered: