Hey everyone,
I thought I'd ask this question here on the google groups in addition to SO.
I'm writing a function in node in a project using Sequelize-Postgres as an ORM.
This is what I got; it's a partial code from the project's spec file:
var stockTeams = [
{name: "Team1"},
{name: "Team2"},
{name: "Team3"},
{name: "Free Agency Team"}
]
var stockPlayers = [
{name: "Player1",
realWorldTeam: "ALB"},
{name: "Player2",
realWorldTeam: "ALB"},
{name: "Player3",
realWorldTeam: "ALK"},
{name: "Player4",
realWorldTeam: "ALK"},
{name: "Player5",
realWorldTeam: "BAL"},
{name: "Player6",
realWorldTeam: "BAL"},
{name: "Player7",
realWorldTeam: "HWI"},
{name: "Player8",
realWorldTeam: "HWI"}
]
var createTeams = function() {
return db.Team.bulkCreate(stockTeams).then(function() {
return db.Player.bulkCreate(stockPlayers)
});
}
And what I want to do with these variables, is to group the stockPlayers by realWorldTeam, and then add each group (e.g. ALB group) to each stockTeam (ALB goes to Team1, ALK goes to Team2). Lastly, when I've gone through all the numbered stock teams, any further players will go to the Free Agency Team.
I've tried using `var players = db.Player.findAll({group: ['realWorldTeam'] })` , but then I've gotten stuck on how to proceed. I've also considered using lodash's ._groupBy, but I'm in a similar position.
Can anyone offer advice? Thanks in advance! Sorry if I forget to add anything.